Anyone know why my EXP giver Gui is throwing up an index error?

This admin GUI is meant to give you EXP, instead it throws up an error, saying ** [ServerScriptService.Script:2: attempt to index number with ‘leaderstats’])**

Server Script =

game.ReplicatedStorage.AddEXP.OnServerEvent:Connect(function(Value,Player)
	Player.leaderstats.EXP.Value = Player.leaderstats.EXP.Value + Value
end)

Local Script -

script.Parent.MouseButton1Click:Connect(function()
	local Value = script.Parent.Parent.AmountValue.Value
	local Name = script.Parent.Parent.PLR.Text
	local Player = game.Players:FindFirstChild(Name)
	game.ReplicatedStorage.AddEXP:FireServer(Value,Player)
end)

the Player parameter is automatically passed first for remote events, you don’t need to send that information because roblox does that. Just send the value argument and it should look like

game.ReplicatedStorage.AddEXP.OnServerEvent:Connect(function(Player, Value) 
	Player.leaderstats.EXP.Value = Player.leaderstats.EXP.Value + Value
end)

You need to switch Value, Player to Player, Value!

Player is passed by default and is always the first argument.

2 Likes

As @HugeCoolboy2007 and @AlgyLacey said, you need to switch the parameters of Value and Player. Also, you don’t need to send the player as an argument for a :FireServer() call because it automatically does it, and puts it as the first parameter.

1 Like