Remote event not working

When i fire the event it print out : Value is a not valid member of player.
I want the script to decrease my health potion stats.

The Local script :

script.Parent.HugePot.TextButton.MouseButton1Click:Connect(function()
	local plr = game.Players.LocalPlayer
	local stat = game.Players.LocalPlayer.Potions.HugeHealthPot


	game.ReplicatedStorage.PotUse:FireServer(plr, stat)
end)

leaderstats (Server Script):

	game.ReplicatedStorage.PotUse.OnServerEvent:Connect(function(plr, stat)
		print(stat)
		
		stat.Value -= 1
		
		plr.Character.Humanoid.Health += 25
	end)

In the Local Script, there’s no need to have plr as an argument for the Remote Function since it gets passed automatically anyway. Removing plr should fix your code.

Really, ...PotUse:FireServer(plr, stat) gets interpreted as ...PotUse:OnServerEvent:Connect(function(plr, plr, stat)) in the Server Script. Consequently, “stat” is actually “plr”, and plr doesn’t have a value which is why it causes an error.

(this is just nitpicking but you can write local stat = plr.Positions.HugeHealthPot since you’ve already written local plr = game.Players.LocalPlayer. :stuck_out_tongue:)

I hope this helps! Feel free to ask any more questions.

I strongly recommend you don’t do these type of remote events, use sanity checks.

This is because you dont need to give the server the plr in the arguments! the first argument given is always the player by default even if you dont give it any arguements!

Simply do
game.ReplicatedStorage.PotUse:FireServer(stat)

I’ve changed both the server script and the local script, and removed the plr

Now it prints out the same thing. It still thinks that “stat” is a player.

Keep plr in the Server Script but remove it from the Local Script. :+1:

1 Like