Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why cant my server script index the player's leaderstats?

Asked by 5 years ago
Edited 5 years ago
1game.ReplicatedStorage["admin money"].OnServerEvent:Connect(function(player,target,money)
2    --if player.PlayerGui.rank:FindFirstChild("admin gui") then
3        print(target)
4        target:WaitForChild("leaderstats").Money.Value = money
5    --end
6end)

ServerScriptService.admin:73: attempt to call method 'WaitForChild' (a nil value) without waitforchild i got ServerScriptService.admin:73: attempt to index local 'leaderstats' (a nil value)

prints: world_kiIIer

local script since it seems like to be needed (should not be needed)

1local player = script.Parent.Parent.player
2local money = script.Parent.Parent.amount
3script.Parent.MouseButton1Click:Connect(function()
4    for i,v in pairs(game.Players:GetChildren()) do
5        if v.Name:match(player.Text) then
6            game.ReplicatedStorage["admin money"]:FireServer(v.Name,money.Text)
7        end
8    end
9end)
0
Why does it print world_killer? Is that he player's name or something? SmartNode 383 — 5y
0
yes its the player name, the money print can only be a number Gameplayer365247v2 1055 — 5y
0
What do you fire to the server? If target isn't a player object, you need to make it one. PhantomVisual 992 — 5y
0
target is a player object Gameplayer365247v2 1055 — 5y
1
v.Name is a string, not the player object... It's like doing: x = "hello" x:WaitForChild("leaderstats"). Make it a player object. PhantomVisual 992 — 5y

1 answer

Log in to vote
2
Answered by 5 years ago
Edited 5 years ago

The target value is just the player's name, instead you should reference the player object:

1local player = script.Parent.Parent.player
2local money = script.Parent.Parent.amount
3script.Parent.MouseButton1Click:Connect(function()
4    for i,v in pairs(game.Players:GetChildren()) do
5        if v.Name:match(player.Text) then
6            game.ReplicatedStorage["admin money"]:FireServer(v,money.Text)
7        end
8    end
9end)

Or something like this for the server-script, it simply finds any player with that specific name.

1game.ReplicatedStorage["admin money"].OnServerEvent:Connect(function(player,target,money)
2    --if player.PlayerGui.rank:FindFirstChild("admin gui") then
3        print(target)
4        game.Players:FindFirstChild(target):WaitForChild("leaderstats").Money.Value = money
5    --end
6end)
Ad

Answer this question