Hi there. Newbie coder here. So I was writing this code, which is supposed to be very simple. If you touch the script.Parent (A part), a timer is called from the starter Gui and is supposed to become visible. The timer counts down from 40 and when it reaches 0, the player dies (resets sorta). Every time I run the script, I get this error, Workspace.Checkpoints.2.Time:2: attempt to index nil with 'GetMouse'. I don't know why. Please help!!
player = game.Players.LocalPlayer
mouse = player:GetMouse()
char = player.Character
h = char:WaitForChild("Humanoid")
seconds = 40
timer = game.StarterGui.Stopwatch.Timer
script.Parent.Touched:Connect(function()
timer.Visible = true
while seconds ~= 0 do
seconds = seconds-1
wait(1)
timer.Text = (seconds.." seconds")
if seconds == 0 then
h.Health = 0
end
end
end)

1 comment
If this is a regular script then LocalPlayer won't work. Since the server isn't a person... Also, game.StarterGui will work but not throw an error, you just won't see it. Use the PlayerGui or index directly from startergui using script.Parent