HUGE problem with touched events

I’m trying to fire a remote event to a player when their char touches the detection area. Sometimes it works, but whenever the layered clothing comes in contact with the area since the “handle” is what’s touching, the parent returned the name of the piece of clothing, not the name of the char. This problem creates errors for me when trying to use getplayerfromchar. Does anyone know a workaround or solution? Thanks!

	local Char = Hit.Parent
		local Player = Players:GetPlayerFromCharacter(Char)
		TriggerGateUI:FireClient(Player, Gate.Name, GatePrices[Gate.Name])

Getting the error, “FireClient: player argument must be a Player object” as layered clothing is returned instead of the char on line one.

I think the problem is that if a body part of the character is touching it, the parent is the character. But if a accessory touches it, the parent is the accessory because the part of the accessory is touching it and the parent is not the character.

This should fix it:

local Char = Hit.Parent
if Char:IsA("Accessory") then
local Player = Players:GetPlayerFromCharacter(Char.Parent)
TriggerGateUI:FireClient(Player, Gate.Name, GatePrices[Gate.Name])
local Player = Players:GetPlayerFromCharacter(Char)
TriggerGateUI:FireClient(Player, Gate.Name, GatePrices[Gate.Name])



tell me if it still does not work.


Thanks! One more question, do you have any idea why I get the error “Coins is not a valid member of Folder “Players.BlazeGamer201002.leaderstats”” when it is?

Screenshot 2023-02-12 at 09.52.48

WaitForChild(leaderstats) and then WaitForChild(Coins)
Maybe that will work

If you are using a localscript to add the Coins value and you are using a normal script to get to it, it cant because only your client has the Coins value. So the server doesnt know that its there. This is only a example. I dont know if you are using local scripts or normal serverscripts. Try changing the client to the server and look if the Coin value is there. You can change to the server when you press the Current Client Button. It looks like this:

Server CLient
(Press it while your game is running of course)

If the Coins Value isnt there then the problem might be that you are using a localscript. So it only exists on your client.

But if the Coins value is there when you look at it on the server client then it might be a diffrent problem. Then you probably should post annother Help and Feedback post on the Scripting Support.

I get the coins value with a local script. You cant modify leader stats with a local script, so perhaps you cant access it either?

I am sorry but I dont really know how to use leaderstats. I have never really used it before so I dont know much about it. I think it might be better to make a new post about it

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.