Ok I want to make a platform where you sell your items for money. However while making the touch thingy, it works in studio. However in the game, when I walk on it, it shows an error. ireClient player argument must be a player object
- Here are the 2 scripts. Does anyone know any problems?
SERVER SCRIPT
script.Parent.Touched:connect(function(part) local plr = part.Parent game.ReplicatedStorage.Events.SellGrass:FireClient(plr) end)
LOCALSCRIPT
local leaderstats = game.Players.LocalPlayer:WaitForChild("leaderstats") game.ReplicatedStorage.Events.SellGrass.OnClientEvent:connect(function(plr) -- Change if event is in different area leaderstats.Money.Value = leaderstats.Money.Value + leaderstats.Grass.Value leaderstats.Grass.Value = 0 end)
There are a few things wrong with your remote event system here, first of which being that you don't need a remote event. There is no reason you should use a localScript to change the player's money/grass values, just do that on the server. As for the error you receive, that is because part.Parent
is the player's character, not the player object itself, a quick fix for this is the following.
local char = part.Parent local player = game.Players:GetPlayerFromCharacter(char) if player then remote:FireClient(player) end
The if
player is needed because char
is not guaranteed to be a character's model, it could be any random part.
But like I said, you don't need to use a remote event in this situation.
Also, this shouldn't have worked in studio.