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

why won't the gui show when the player touches a block?

Asked by
mewtify 26
4 years ago
Edited 4 years ago

here is my code, I get no errors in output.

local touched = false
local function onTouch(hit)
end
workspace.indicator1.Touched:Connect(onTouch)
local function onTouch(hit)
    if (touched == false) then
        touched = true
        if game.Players.LocalPlayer.PlayerGui.ScreenGui.Enabled ~= true then
            if (hit.Parent:FindFirstChild("Humanoid") ~= nil) then
                game.Players.LocalPlayer.PlayerGui.ScreenGui.Enabled = true
                    setText("Hello!")
            end
        end 
    end
end

workspace.indicator1.Touched:Connect(onTouch)

I really don't know why it wouldn't work, but basically I am trying to make it so when you touch the block, the gui shows and the text of the gui changes to "Hello!" then the gui will disappear (didn't add that yet!) and when you touch the block again, the gui won't come up and nothing will happen. I only want it to occur once. any help will be appreciated I have been trying to figure it out for days now, and I am new to coding so sorry if this is a dumb question thank you!

1 answer

Log in to vote
1
Answered by
RAFA1608 543 Moderation Voter
4 years ago
Edited 4 years ago
local touched = false
local function onTouch(hit)
    if (touched == false) then
        --touched = true --this doesnt check if touched is a humanoid or not, therefore not letting an actual humanoid interact with it
        if game.Players.LocalPlayer.PlayerGui.ScreenGui.Enabled ~= true then
            if (hit.Parent:FindFirstChild("Humanoid") ~= nil) then
                game.Players.LocalPlayer.PlayerGui.ScreenGui.Enabled = true
                    touched = true
                    setText("Hello!")
                    delay(3, function()
                          touched = false
                    end)
            end
        end 
    end
end

workspace.indicator1.Touched:Connect(onTouch)

I think thats whats wrong. Also, why are there 2 functions of the same name? Edit: I fixed the script. It missed a ")" next to delay(3,function().

0
Thank you for your answer! And that's my bad, I most likely did that during editing the coding over and over again. I also got the error in the output, "Expected ')' (to close '(' at line 36), got 'end'" I'm not sure what I would change but thank you! mewtify 26 — 4y
0
Fixed RAFA1608 543 — 4y
0
thank you so much, that worked, but after 3 seconds i can touch it and the gui will come up. if I make the delay a really high number, would that work so the player would move on by the time the times up? thank you! mewtify 26 — 4y
Ad

Answer this question