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

Attempt to call a nil value?[Unsolved]

Asked by 9 years ago

If you downvote this, please post why you did! The script is supposed to print (name of player) sat on seat, and then it is supposed to make the recover text (inside recovering GUI) visible! Why isn't that happening? Here is the script

local plr = nil;
script.Parent.ChildAdded:connect(function (obj)
if (not obj:IsA("Weld")) then return; end
if (plr ~= nil) then return; end
local tors = obj.Part1;
local char = tors.Parent;
plr = game.Players:findFirstChild(char.Name);
if (plr == nil) then return; end
print(plr.Name.." sat on this seat");
wait(1)--my part starts here
function onTouched(hit)
    print("touched")
    print(hit.Name)
    print(hit.Parent.Name)
    plr.PlayerGui.Recovering.Recover.Visible = true
end
end);
script.Parent.Parent.Foot1.Touched:connect(onTouched)

Please help!!! Thank you!!! P.S. It does print _____ sat on this seat

1
Can you provide an error message? Thewsomeguy 448 — 9y
0
"attempt to call a nil value" and that is it yogipanda123 120 — 9y

1 answer

Log in to vote
2
Answered by 9 years ago

I don't really understand what you are trying to do with the following lines as they are opposite arguments?

if (plr ~= nil) then return; end
if (plr == nil) then return; end 

The script below needs to be placed into the seat to work.

I have added remove gui if needed.

--player sat down show gui
script.Parent.ChildAdded:connect(function (ins)

    if ins.Name == "SeatWeld" then -- child is weld, i dont know if this is a default name?
        local wplr = ins.Part1.Parent --player
        print(wplr) -- workspace character

        local gplr = game.Players:GetPlayerFromCharacter(wplr) -- get game player
        print(gplr) -- game players

        if gplr ~= nil then -- checks in plr exists
            gplr.PlayerGui.ScreenGui.Frame.Visible = true -- show gui ot text
        end

    end
end)

--player stood up hide gui
script.Parent.ChildRemoved:connect(function (ins)

    if ins.Name == "SeatWeld" then -- child is weld, i dont know if this is a default name?
        local wplr = ins.Part1.Parent --player
        print(wplr) -- workspace character

        local gplr = game.Players:GetPlayerFromCharacter(wplr) -- get game player
        print(gplr) -- game players

        if gplr ~= nil then  -- checks in plr exists
            gplr.PlayerGui.ScreenGui.Frame.Visible = false -- show gui ot text
        end

    end
end)
0
That must have taken some time, but i am sorry I don't want it when they get in the seat,  it needs to be when the vehicle they are in hits the ground the GUI pops up(as it will be falling out of the sky) yogipanda123 120 — 9y
Ad

Answer this question