Why is my script not working

My script in a part isnt working, there isnt any errors in the output but nothing is happening! Thanks

local cooldown = false

script.Parent.Touched:Connect(function(hit)
	local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if player then
		if not cooldown then
			cooldown = true
			local rnad = math.random(1000,100000)
			player.leaderstats.Candy.Value += rnad
			task.wait(20)
			cooldown = false
		end
	end
end)
2 Likes

So is the script a localscript ?

Could you make sure the leaderstat object is actually that name (no like Leaderstats and stuff).

1 Like

I don’t think that has anything to do with the script itself

Hello!

player.leaderstats.Candy.Value += rnad is the problem in your script, this should fix it: player.leaderstats.Candy.Value = player.leaderstats.Candy.Value + rnad.

Always do Value = Value + what you want to add or subtract.

I hope this helps!

You can do that in Luau, and it does the same as what you said. Along with that it makes readability easier


The script itself is normal, make sure the part is in workspace and the script is enabled.

1 Like

Thanks for your help, that should work but I figured the problem was just me being dumb and some caps lock issue! Thanks!

I’m going to give you some feedback here:
wait() is deprecated, task.wait() is more precise
And for this:

I’m just trying to help you script more efficiently, don’t take these as an insult

1 Like

yeah i don’t know if you noticed but that person uses ChatGPT for every post they make…

they don’t know that scripting support is for experienced scripters… not writing off of an AI :rofl:

Plagarism at it’s finest

1 Like

Yeah I had the same vision. Value = Value + Value instead of Value += Value :rofl:

Excuse me sir. I apologize if you think that I’m unsuccessful. But I was replying for 15-20 minutes if you noticed. I created only 2 posts about scripting support. Please be kind while replying a member of this forum. People have to create formal posts, it is normal that you thought I’m a GPT-3 built AI.
We’ll receive an off-topic feedback if we keep talking about other topics.

Thank you for being polite. I usually work with phyton, I"m sorry that I’m late for Lua.

Have a nice day, Neweve2323/grassperson

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