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

Touched & TouchEnded not executing code block inside? [Solved]

I wrote this code, then I tested it. It worked, so I resize and play around with the part, and it suddenly stops working! Here is my code (Code block was too small, it shifted some things so sorry if it is messy):

script.Parent.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        player.PlayerGui.test1.safe.TextLabel.TextColor3 = Color3.fromRGB(31, 198, 28)
    end)


script.Parent.TouchEnded:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        player.PlayerGui.test1.safe.TextLabel.TextColor3 = Color3.fromRGB(198, 52, 54)
    end)

I want it so that when you touch the brick, there is a GUI that says safe. If you are outside of the brick (Not touching it) It would become red. If you are inside the brick (touching) then it is green. I can't figure this out.

I would really appreciate some help.

1 answer

I figured out minutes after, lol. I forgot to add a debounce. The code should be:

script.Parent.Touched:Connect(function(hit)
	    local Debounce = false
        if Debounce == false then
        Debounce = true
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        player.PlayerGui.test1.safe.TextLabel.TextColor3 = Color3.fromRGB(31, 198, 28)
        wait ()
        Debounce = false
    end
end)


script.Parent.TouchEnded:Connect(function(hit)
		local Debounce = false
        if Debounce == false then
        Debounce = true
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        player.PlayerGui.test1.safe.TextLabel.TextColor3 = Color3.fromRGB(198, 52, 54)
        wait ()
        Debounce = false
    end
end)

2 comments

0

I recommend making the debounce wait atleast a second for better performance.

0

Ok, I'll try that! Thanks for the suggestion!

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