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

Need Help Making Script That When A Player Already Touched They Cant Touch Again?

So Far In My Script Is

--{jamiethegreatQ777}--

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

	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("Stage") --Get money
			cash.Value  = cash.Value +1 --increase amount of money by the number displayed here (500000)
			wait(5) --wait-time before button works again
		end

	end

	ting = 0 --remove debounce
	end

end

script.Parent.Touched:connect(onTouched)

But The Wait Just Means The Player Can Wait That Long And Just Get Another Stage For Doing Nothing Please Help

1 answer

✓ Accepted answer
-- Its easy just do this 
--{jamiethegreatQ777}--

local ting = false --debouncer(changed it )

function onTouched(hit)

    if not ting then --debounce check(changes it)
    ting = true  --activate debounce(changed it )

    check = hit.Parent:FindFirstChild("Humanoid") --Find the human that touched the button

    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("Stage") --Get money
            cash.Value  = cash.Value +1 --increase amount of money by the number displayed here (500000)
            wait(5) --wait-time before button works again
        end

    end

    ting = false --remove debounce(changed it )
    end

end

script.Parent.Touched:connect(onTouched)



1 comment

0

Thanks :)

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