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

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

Asked by
cailir 284 Moderation Voter
5 years ago

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

Log in to vote
2
Answered by
Leamir 3138 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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

0
upvote from me User#19524 175 — 5y
1
Thanks =D Leamir 3138 — 5y
0
line4 gotta be Occupant.Jump not Humanoid.Jump lol User#19524 175 — 5y
1
Ops... Leamir 3138 — 5y
1
Solved Leamir 3138 — 5y
Ad
Log in to vote
-1
Answered by 5 years ago

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

Answer this question