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

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

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

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().

3 comments

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!

0

Fixed

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!

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