Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Attempt to call a nil value?[Unsolved]

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

2 comments

1

Can you provide an error message?

0

"attempt to call a nil value" and that is it

1 answer

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)

1 comment

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.