【问题标题】:How to give money to player which username is stored in a string value - Roblox lua如何给存储在字符串值中的用户名的玩家钱 - Roblox lua
【发布时间】:2021-03-01 10:36:23
【问题描述】:

所以我在 Roblox 上制作了一款游戏,您可以在其中捡起物品并出售它们。但是,销售脚本是普通脚本(在服务器上运行),我不能使用

Game:GetService("Players").LocalPlayer

找出把钱给谁。用户拿起的对象有一个

Owner

value,当他们触摸它时,它会将其更改为他们的用户名。因此,当对象接触到出售部分时,它会看着所有者,并将钱给他们(存储在称为所有者的数字值中)。

这是我当前的代码:

local part = script.Parent

local function onPartTouched(otherPart)--otherPart is the part that touched it
    if otherPart:FindFirstChild("Owner") == nil then
    else
        local owner = game.Players..otherPart.Owner.Value
        getowner.leaderstats.Bucks.Value = getprice.leaderstats.Bucks.Value + otherPart.Price.Value
        otherPart.Parent = game.ServerStorage
    end
end

part.Touched:Connect(onPartTouched)

【问题讨论】:

    标签: lua concatenation roblox


    【解决方案1】:

    你可以做 game.Players[value.Value]

    【讨论】:

    • 你不需要连接。如果您需要,这里是代码。 local part = script.Parent local function onPartTouched(otherPart)--otherPart 是触及它的部分 if otherPart:FindFirstChild("Owner") == nil then else local owner = game.Players[otherPart.Owner.Value] getowner. leaderstats.Bucks.Value = getprice.leaderstats.Bucks.Value + otherPart.Price.Value otherPart.Parent = game.ServerStorage end end part.Touched:Connect(onPartTouched)
    • 您应该使用分析器下方的edit 功能来编辑您的答案,而不是将代码编写为注释。更容易阅读! :)
    【解决方案2】:

    随便用

    Game.Players.LocalPlayer
    

    也只是以正确的格式编写@agents 答案。

    local part = script.Parent 
    local function onPartTouched(otherPart)
        if otherPart:FindFirstChild("Owner") == nil then 
        else 
            local owner = game.Players[otherPart.Owner.Value] 
            getowner.leaderstats.Bucks.Value = getprice.leaderstats.Bucks.Value +otherPart.Price.Value 
            otherPart.Parent = game.ServerStorage 
        end 
    end 
    part.Touched:Connect(onPartTouched)
    

    【讨论】:

    • 我正在使用服务器脚本,而Game.Players.LocalPlayer 在服务器上不起作用。另外,这个问题已经解决了,所以......感谢您的贡献,但也许检查一下它是否已经被 awnsered,这样您就不必浪费时间编写 awnser。
    • 我说使用本地脚本
    • 我的回答至少对我来说似乎是有效且无滞后的。
    • 我很确定本地脚本在客户端上运行,除非在服务器上执行也只在客户端上,并且不会复制(filtering enabled,roblox 反作弊)
    猜你喜欢
    • 2022-10-05
    • 2022-06-21
    • 2020-04-25
    • 2021-10-17
    • 1970-01-01
    • 2019-06-26
    • 2020-09-13
    • 2020-11-01
    • 1970-01-01
    相关资源
    最近更新 更多