如何给用户名存储在字符串值中的玩家钱 - Roblox lua
How to give money to player which username is stored in a string value - Roblox lua
所以我正在 Roblox 上制作一款游戏,您可以在其中拾取物品并出售它们。然而,销售脚本是一个普通脚本(服务器上运行),我不能使用
Game:GetService("Players").LocalPlayer
找谁给钱。用户拾取的对象有一个
Owner
value,当他们触摸它时,它会将其更改为他们的用户名。所以当物体接触到销售部分时,它会看着所有者,并将钱交给他们(存储在一个名为 Owner 的数值中)。
这是我当前的代码:
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)
你可以做到 game.Players[value.Value]
只需使用
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)
所以我正在 Roblox 上制作一款游戏,您可以在其中拾取物品并出售它们。然而,销售脚本是一个普通脚本(服务器上运行),我不能使用
Game:GetService("Players").LocalPlayer
找谁给钱。用户拾取的对象有一个
Owner
value,当他们触摸它时,它会将其更改为他们的用户名。所以当物体接触到销售部分时,它会看着所有者,并将钱交给他们(存储在一个名为 Owner 的数值中)。
这是我当前的代码:
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)
你可以做到 game.Players[value.Value]
只需使用
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)