This is in a LocalScript in an ImageButton in a ScreenGui in StarterGui.
player = game.Players.LocalPlayer timer = script.Parent.Timer enabled = true function onClick(click) if player.ItemCounter["Quick Mushroom"].Value > 0 and enabled == true then enabled = false player.ItemCounter["Quick Mushroom"].Value = player.ItemCounter["Quick Mushroom"].Value - 1 player.Character.Humanoid.WalkSpeed = 48 timer.Visible = true timer.Text = "2:00" minutes = 2 for seconds = 120, 0, -1 do local seconds2 = seconds - 60 local secondsdisplay = seconds2 if seconds == 119 then minutes = 1 end if seconds == 59 then minutes = 0 end if seconds2 < 10 then secondsdisplay = "0"..seconds2 end if seconds < 60 then secondsdisplay = seconds end if seconds < 10 then secondsdisplay = "0"..seconds end if secondsdisplay == 60 then secondsdisplay = "00" end timer.Text = minutes..":"..secondsdisplay wait(1) end player.Character.Humanoid.WalkSpeed = 24 timer.Visible = false enabled = true end end script.Parent.MouseButton1Click:connect(onClick)
The script runs just fine in studio, but when playing in-game, an error appears on Line 2 stating that "Timer" is not a valid member of ImageButton. However, when going into Studio, there is indeed a TextLabel in the ImageButton named "Timer". What's going on here?
The problem is that sometimes the script loads before the actual gui, so 'Timer' may be nil at the moment that your script excecutes.
To fix this, I suggest waiting until 'Timer' has loaded, or check if it has loaded.
Also, your timer could use some touch ups.
local player = game.Players.LocalPlayer local enabled = true script.Parent.MouseButton1Click:connect(function() script.Parent:WaitForChild("Timer") local timer = script.Parent:FindFirstChild("Timer") local m = player.ItemCounter["Quick Mushroom"] if m.Value > 0 and enabled == true then enabled = false m.Value = m.Value - 1 player.Character.Humanoid.WalkSpeed = 48 timer.Visible = true timer.Text = "2:00" local minutes = 2 for i = (minutes * 60), 0, -1 do local minutes = math.floor( i / 60) local seconds = i - (minutes * 60) if tostring(seconds):len() < 2 then seconds = tonumber("0"..tostring(seconds)) end timer.Text = tostring(minutes)..":"..tostring(seconds) end player.Character.Humanoid.WalkSpeed = 24 timer.Visible = false enabled = true end end)
timer = script.Parent:WaitForChild("Timer")
Try that. It might not work tho...