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

No errors popping up once I execute script..?

So I am making a script that will make a text pop up if you click on a brick. It doesn't work though, and there are no errors that popped up.

script.Parent.ClickDetector.MouseClick:Connect(function(onClick)
end)
	    game.Players.LocalPlayer.PlayerGui.DoorBGui.Locked.Visible = true
	
    wait (5) game.Players.LocalPlayer.PlayerGui.DoorBGui.Locked.Visible = false

1 comment

0

The code needs to be within the function scope

2 answers

✓ Accepted answer

You didn't write the code inside of the function

script.Parent.ClickDetector.MouseClick:Connect(function(onClick)
	--This is where you should put the function's code

end) --This is the end of the function
	--This is outside of the function so it won't fire when the function is called upon
        game.Players.LocalPlayer.PlayerGui.DoorBGui.Locked.Visible = true

    wait (5) game.Players.LocalPlayer.PlayerGui.DoorBGui.Locked.Visible = false

So if you just placed your code inside the function like this

script.Parent.ClickDetector.MouseClick:Connect(function(onClick)
        game.Players.LocalPlayer.PlayerGui.DoorBGui.Locked.Visible = true
   	 wait(5)
	game.Players.LocalPlayer.PlayerGui.DoorBGui.Locked.Visible = false
end)

Everything should work as intended

Try this script:

local Part = script.Parent

script.Parent.ClickDetector.MouseClick:Connect(function(HIT)
	local H = HIT.Parent:FindFirstChild("Humanoid")
	if H then 
		local Player = game.Players:GetPlayerFromCharacter(HIT.Parent)
		game.Players.LocalPlayer.PlayerGui.DoorBGui.Locked.Visible = true
		wait (5) 
		game.Players.LocalPlayer.PlayerGui.DoorBGui.Locked.Visible = false
	end
end)

1 comment

0

that doesnt work

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