Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I get this script to work once per player?

Ok so I made a script where you touch a part and you get a Point in the leaderboard. I called the Points Stars. How do I get this script to work once for each player. For example a guy gets the star and in the leaderboards it says he has 1 star. Then he goes up to it again and he doesn't get another star from that one because he already has it. Please help I kept trying but when I did it just didn't work! :(

local ting = 0 --debouncer

function onTouched(hit)

	if ting == 0 then --debounce check
	ting = 1 --activate debounce
	check = hit.Parent:FindFirstChild("Humanoid") --Find the human that touched the button
	player = hit.Parent
	
	if check ~= nil then --If a human is found, then

		local user = game.Players:GetPlayerFromCharacter(hit.Parent) --get player from touching human
		local stats = user:findFirstChild("leaderstats") --Find moneyholder

		if stats ~= nil then --If moneyholder exists then
			
			local cash = stats:findFirstChild("Stars") --Get money
			
			cash.Value  = cash.Value +1 --increase amount of money by the number displayed here (1)
			wait(1)
			check.Health = 0
			wait(4) --wait-time before button works again
			
			end
		end

	end

	ting = 0 --remove debounce
	end

script.Parent.Touched:connect(onTouched)

2 comments

0

You could always add a value to the players, then if they touch it, it makes it true. Or something..

0

Hmm but if I make the star insert a value there will be lots of values in your character and it could glitch. I want it to go by the player's name who touched it and then if they touch it again it just adds 0.

1 answer

Add a value to the players, example;

If you add a value to the players, and they touch the 'Star', it makes it true.

1 comment

0

Oh and also I found a glitch where you get lots of stars when touching the part that supposed to give you one. I even made it kill too but that didn't help. Please help me!

This discussion is preserved as it was. New answers, comments, and votes are closed.