如何给玩家转账,其中玩家用户名存储在字符串值中 - Roblox lua

我正在Roblox上制作一个游戏,玩家可以拾起物品并出售。然而,出售脚本是普通脚本(在服务器上运行),我不能使用

Game:GetService("Players").LocalPlayer

来查找要转账的玩家。用户拾起物品时,该物品具有

Owner

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

这是我的当前代码:

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)
点赞
用户14662604
用户14662604

你可以使用 markdown 格式 game.Players\[value.Value\]

2020-11-18 14:18:09
用户16740472
用户16740472

只需使用

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)
2021-10-23 09:19:44