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

Why doesn't my script enable and disable gui?

I'm not a person who scripts a lot. I'm trying to make a script that enables a GUI when a player touches a brick, counts down the text, and disables the GUI. For some reason the GUI will not appear.

S = game.StarterGui.SpeedGUI
T = game.StarterGui.SpeedGUI.MainFrame.Time

function Ontouched(hit)
	S.Enabled = true
	T.Text = "15 Seconds"
	wait(1)
	T.Text = "14 Seconds"
	wait(1)
	T.Text = "13 Seconds"
	wait(1)
	T.Text = "12 Seconds"
	wait(1)
	T.Text = "11 Seconds"
	wait(1)
	T.Text = "10 Seconds"
	wait(1)
	T.Text = "9 Seconds"
	wait(1)
	T.Text = "8 Seconds"
	wait(1)
	T.Text = "7 Seconds"
	wait(1)
	T.Text = "6 Seconds"
	wait(1)
	T.Text = "5 Seconds"
	wait(1)
	T.Text = "4 Seconds"
	wait(1)
	T.Text = "3 Seconds"
	wait(1)
	T.Text = "2 Seconds"
	wait(1)
	T.Text = "1 Second"
	wait(1)
	S.Enabled = false
end

I think it has something to do with function Ontouched(hit) but I'm not sure.

1 answer

✓ Accepted answer

This is quite a common mistake. What you are doing is changing the StarterGui instead of the PlayerGui. You also don't actually have a .Touched event to trigger the function.

Here's a fixed version

local part = script.Parent

part.Touched:Connect(function(hit)
	local player = game.Players:FindFirstChild(hit.Parent.Name)
	if player ~= nil then -- Check to see if the part that touched was a character of a player
		local speedGui = player.PlayerGui.SpeedGUI
		for i = 1, 15 do
			wait(1)
			speedGui.MainFrame.Time.Text = (15 - i)
		end
		speedGui.Enabled = false
	end
end)

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