Hello! I'm trying to make the player jump when it seats on a vehicle. The script is giving the following error:
Workspace.City.Model.Model.Drive.Script:3: attempt to index a nil value
The Script:
while wait() do if script.Parent.Occupant ~= nil then if game.Players:GetPlayerFromCharacter(script.Parent.Occupant):GetRankInGroup(3894675) == 0 then script.Parent.Occupant.Humanoid.Jump = true end end end
Thanks for your help!
Hello, cailir!
A seat ocupant is a HUMANOID, so the Ocupant.Parent
is the player model!
while wait() do if script.Parent.Occupant ~= nil then if game.Players:GetPlayerFromCharacter(script.Parent.Occupant.Parent):GetRankInGroup(3894675) == 0 then script.Parent.Occupant.Jump = true end end end
Good Luck with your games
The Occupant property is a reference of a Humanoid
, not a player's character. Also, you should check if a player exists, before checking if they're in a group - it could error the way you're doing it.
while wait() do local player = game.Players:GetPlayerFromCharacter(script.Parent.Occupant.Parent) if player then if player:GetRankInGroup(your group id) == 0 then player.Character.Humanoid.Jump = true end end end
Also, where I have 'your group id',' is where you put the id of your group. I couldn't see it because I'm on mobile