Hey!
Error is 19:35:52.549 - Workspace.ObbyStructure.Second.Part.Script:20: attempt to index a nil value
So I am basically trying to create a script that when a person stands on a part in an obby that if they are still in a specified radius of the object after 3 seconds, they die. I also want to alert them after with a message telling them why they died. I'm getting the error on line 20. The script is:
local part = script.Parent local radius = 5 game.StarterGui.ScreenGui.X.Visible = false part.Touched:connect(function(hit) local h = game.Players:GetPlayerFromCharacter(hit.Parent) if h then local player = hit.Parent game.Players:GetPlayerFromCharacter(hit.Parent).PlayerGui.ScreenGui.Frame.Visible = true wait(3) game.Players:GetPlayerFromCharacter(hit.Parent).PlayerGui.ScreenGui.Frame.Visible = false wait(3) if h:DistanceFromCharacter(part.Position) < radius then hit.Parent.Humanoid.Health = 0 wait(5) game.Players:GetPlayerFromCharacter(hit.Parent).PlayerGui.ScreenGui.X.Visible = true for i = 0,1,.1 do wait(0.6) game.Players:GetPlayerFromCharacter(hit.Parent).PlayerGui.ScreenGui.X.BackgroundTransparency = i if i == 1 then game.Players:GetPlayerFromCharacter(hit.Parent).PlayerGui.ScreenGui.X.Visible = false break end end end end end)
Any help on why this won't work?
--
You may have to view source to see full code
--
Thanks! Sam