Having Trouble making a Leaderstat zone

Hi,

I am trying to make a script which enables Leaderstats once a part is touched and disabled once the touching is done, but after trying lots of different solutions I have failed.

I do not understand why this is occouring and I need help making this

ServerSided Script for .touched Event:

script.Parent.Touched:Connect(function(Part)	
	if Part and Part.Parent:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(Part.Parent) then
		print("something")
		script.RemoteEvent:FireClient(game.Players:GetPlayerFromCharacter(Part.Parent))
	end
end)

script.Parent.TouchEnded:Connect(function(Part)
	if Part and Part.Parent:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(Part.Parent) then
		warn("ended")
		script.RemoteEvent:FireClient(game.Players:GetPlayerFromCharacter(Part.Parent))
	end
end)

LocalScript which contains the Event:

script.Parent.RemoteEvent.OnClientEvent:Connect(function(BoolVal:BoolValue)
	warn(BoolVal)
	game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, BoolVal)
end)

after doing some testing.
the function works it prints Something and ended whenever a player touches them but sadly the event does nothing.

1 Like

you made a silly mistake if not passing a boolean argument for the remote event on the server side for the touched events.Its always gonna return nil for BoolVal.

oh, I didn’t know that. how can I fix this silly mistake?

Try this code

script.Parent.Touched:Connect(function(Part)	
	if Part and Part.Parent:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(Part.Parent) then
		print("something")
		script.RemoteEvent:FireClient(game.Players:GetPlayerFromCharacter(Part.Parent),true)
	end
end)

script.Parent.TouchEnded:Connect(function(Part)
	if Part and Part.Parent:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(Part.Parent) then
		warn("ended")
		script.RemoteEvent:FireClient(game.Players:GetPlayerFromCharacter(Part.Parent),false)
	end
end)

I noticed how I forgot to paste the old script when I provided my serversided script.

I have sadly already tried that, the original script was like that but it still didn’t work.

I retried it right now and it still wasnt working.

where is your local script located

it is located inside the serverscript.

image

You cant have a local script with a script.Move it to starterplayerscripts and put remoteEvent in replicatedStorage

You should put Boolean instead of BoolValue, If you want to use BoolValue, you need to put BoolValue.Value, not just a BoolValue Instance

alright ill try that now. it worked tysm

ill try that next time thank you for the tip. but shouldn’t it still print the thing its supposed to print?

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