Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

5 comments

0

Why does it print world_killer? Is that he player's name or something?

0

yes its the player name, the money print can only be a number

0

What do you fire to the server? If target isn't a player object, you need to make it one.

0

target is a player object

1

v.Name is a string, not the player object... It's like doing: x = "hello" x:WaitForChild("leaderstats"). Make it a player object.

1 answer

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.