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
game.ReplicatedStorage["admin money"].OnServerEvent:Connect(function(player,target,money)
    --if player.PlayerGui.rank:FindFirstChild("admin gui") then
        print(target)
        target:WaitForChild("leaderstats").Money.Value = money
    --end
end)

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)

local player = script.Parent.Parent.player
local money = script.Parent.Parent.amount
script.Parent.MouseButton1Click:Connect(function()
    for i,v in pairs(game.Players:GetChildren()) do
        if v.Name:match(player.Text) then
            game.ReplicatedStorage["admin money"]:FireServer(v.Name,money.Text)
        end
    end
end)
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:

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

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

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

Answer this question