Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited by DeceptiveCaster 5 years ago

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

Log in to vote
0
Answered by 5 years ago

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)
0
I recommend making the debounce wait atleast a second for better performance. bluzorro 417 — 5y
0
Ok, I'll try that! Thanks for the suggestion! lukasdim -3 — 5y
Ad

Answer this question