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

Player touching object multiple times?

So I started to make a tycoon thing from scratch to learn but whenever the player touches a button it says the player has touched it like 3 times and makes the player pay 3 times as much for the thing. I have tried making a variable where when they touch the button it increases and it can't decrease the money again but it still gets rid of the money. Please help.

2 comments

0

I'm confused, could you give an example?

0

@Dovydas1118 Is correct. Use debounces (checks) to see if they can step on it again.

2 answers

Here's what I think you're trying to do.

local debounce = 3 --false is not activated, true is activated
local CanTouch = true
local timer = 2 --Change this to any number
script.Parent.Touched:Connect(function()
    if debounce <= 0  and CanTouch == true then 
CanTouch = false
        debounce = debounce - 1
        --code here
wait(timer)
       	CanTouch = true
    end
end)

Debounce. Debounce stops everything for a short amount of time. Put a variable called debounce and set it to false. It prevents 'spamming'.

local debounce = false --false is not activated, true is activated
local timer = 30 --Change this to any number
script.Parent.Touched:Connect(function()
	if not debounce then --Alternative: if debounce == false
		debounce = true
		--code here
		wait(timer)
		debounce = false
	end
end)

7 comments

0

I don't know if this is what he was on about... "player has touched it like 3 times and makes the player pay 3 times as much for the thing" i know you want rep but you're really not helping anybody by spamming answers and not understanding. So please try to ask before giving an answer (unless it's really obvious).

0

@VAHMPIN I explain things well.

1

It's not explaining if your giving out answers without the actual question being answered, did he ask for a wait time? - he's asking about increasing a variable, read before you answer, only answering for reputation is pitiful. 

0

@VAHMPIN 'only answering for reputation is pitiful' I bet you wanna do the same. I'm only giving a starting point, and not a full answer. Isn't that the point of scriptinghelpers? to help but not to give answers?

0

Dovydas1118 you are a disgrace to this website, this it to help people, not to gain your reputation on an online game. Learn your place.

0

@GoreDemons . Sure. I am now considered an enemy, apparently. I am not even trying to be rude.

0

GoreDemons. Dovy is one of the most helpful people on this website. DONT CALL HIM A DISGRACE

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