Help checking players coins

Hello Devs! so, i was working on a simulator, but im facing a problem.
Im currently making some portals, i want that if the player has enough coins (“Clicks in my game”) , teleport him to some place
Captura de pantalla (31)

I tried this Code but its not working

local player = game.Players.LocalPlayer
local Clicks = player.leaderstats.Clicks.Value

local PlayerHit = hit.Parent
if PlayerHit then
local Torso = PlayerHit.HumanoidRootPart
if Torso then
if Clicks >= 500 then
Clicks -= 500
Torso.Position =, 7.462, -227.165)

This is my leaderstats folder
Captura de pantalla (35)

Is there a way to fix it?
Thanks for reading!

Is this a Script or a LocalScript?
You can also put print(Clicks) to see how many clicks are there for troubleshooting.

1 Like

Its a Script, inside a part called “Teleport” , that wen touched teleports the player

You say you are using a Script but you’re calling LocalPlayer?
LocalPlayer can only be called from LocalScripts on the client
You would want to get the player inside your hit function using

local plr = Players:GetPlayerFromCharacter(PlayerHit)

It’ll return nil if it can’t find a player so you’d just have to change

if PlayerHit then
-- to
if plr then

(Also you’d have get the leaderstats and the clicks value inside)

1 Like

Thanks! i will definetly try that :grinning_face_with_smiling_eyes:

Im not the best at scripting but i think ik why your code isnt working
i dont think local clicks = game.leaderstats.clicks.value works remove the .value and then when removing players clicks do clicks.value = clicks.value - 500

I’m wrighting this on a phone not keyboard

1 Like

I dont understand, What do you mean with get?

Like you do with properties and things like that


“Getting” the children/properties of a object is normally done like this

1 Like

i think that should work

local DB = false	

	if hit.Parent:FindFirstChild("Humanoid")then
		if DB == false then
			DB = true
			local char = hit.Parent
			local plr = game.Players:GetPlayerFromCharacter(char)		
			if plr.leaderstats.Clicks.Value >= 500 then	
				plr.leaderstats.Clicks.Value -= 500
				char.HumanoidRootPart.CFrame =, 7.462, -227.165)
			DB = false	

1 Like