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.

01local touched = false
02local function onTouch(hit)
03end
04workspace.indicator1.Touched:Connect(onTouch)
05local function onTouch(hit)
06    if (touched == false) then
07        touched = true
08        if game.Players.LocalPlayer.PlayerGui.ScreenGui.Enabled ~= true then
09            if (hit.Parent:FindFirstChild("Humanoid") ~= nil) then
10                game.Players.LocalPlayer.PlayerGui.ScreenGui.Enabled = true
11                    setText("Hello!")
12            end
13        end
14    end
15end
16 
17workspace.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
01local touched = false
02local function onTouch(hit)
03    if (touched == false) then
04        --touched = true --this doesnt check if touched is a humanoid or not, therefore not letting an actual humanoid interact with it
05        if game.Players.LocalPlayer.PlayerGui.ScreenGui.Enabled ~= true then
06            if (hit.Parent:FindFirstChild("Humanoid") ~= nil) then
07                game.Players.LocalPlayer.PlayerGui.ScreenGui.Enabled = true
08                    touched = true
09                    setText("Hello!")
10                    delay(3, function()
11                          touched = false
12                    end)
13            end
14        end
15    end
16end
17 
18workspace.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