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

Player jump when sit on a vehicle if player is not in group. Can anyone help?

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!

2 answers

✓ Accepted answer

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

5 comments

0

upvote from me

1

Thanks =D

0

line4 gotta be Occupant.Jump not Humanoid.Jump lol

1

Ops...

1

Solved

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

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