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

4 comments
What is ScreenGu? On line20 you ScreenGui equal to i. You can't set an object equal to a number.
Check if the player exists prior to indexing them
What would be the best way to to that? Goulstem
Astreal on line 20 I have ""game.Players:GetPlayerFromCharacter(hit.Parent).PlayerGui.ScreenGui.X.BackgroundTransparency = i"" which is me trying to fade out the text