Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Getting an index nil value error on my game script, Any help?

Asked by 7 years ago
Edited 7 years ago

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

0
What is ScreenGu? On line20 you ScreenGui equal to i. You can't set an object equal to a number. AstrealDev 728 — 7y
0
Check if the player exists prior to indexing them Goulstem 8144 — 7y
0
What would be the best way to to that? Goulstem samennis1 0 — 7y
0
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 samennis1 0 — 7y

Answer this question