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

Vehicle seat only for group Id?

Asked by 4 years ago
Edited 4 years ago

Hi! So Is it possible to make this script use a group id instead of a certain player name?

local seat = script.Parent

local AllowedPlayers = {

["wevetments"] = {false},
["Driftyzzz"] = {true}
}

local function OnChildAdded(Child)
 if Child.Name == "SeatWeld" and Child:IsA("Weld") then
  local Character = Child.Part1.Parent
  if AllowedPlayers[Character.Name] then
   if AllowedPlayers[Character.Name][1] == false then
    wait(0.1)
    seat.Disabled = true
    wait(1)
    seat.Disabled = false
   end
  else
   wait(0.1)
   seat.Disabled = true
   wait(1)
   seat.Disabled = false
  end
 end
end

seat.ChildAdded:Connect(OnChildAdded)

Thanks!

1 answer

Log in to vote
0
Answered by
Ankur_007 290 Moderation Voter
4 years ago
Edited 4 years ago

You can use the Player instance's method Player:IsInGroup() to see whether a given player is in a group, after that it's just a matter of incorporating your method into an if then block.

Since we (presumably) want the block of code to execute when a given player is NOT in the group, we just place a not right before our Player:IsInGroup() (since if a player isn't in the group, Player:IsInGroup() evaluates to false, and not false == true)

Note: If you want the block to run for every player who IS in the group, just remove the not from the condition

local seat = script.Parent

local groupId = "123456789"

local function OnChildAdded(Child)
    if Child.Name == "SeatWeld" and Child:IsA("Weld") then
        local Character = Child.Part1.Parent
        local player = game.Players:GetPlayerFromCharacter(Character)
        if not player:IsInGroup(groupId) then
            wait(0.1)
            seat.Disabled = true
            wait(1)
            seat.Disabled = false
        end
    end
end

seat.ChildAdded:Connect(OnChildAdded)


Hope that helped you, feel free to ask any questions or point out any mistakes in the comments!

0
Thanks! djstijn321 6 — 4y
Ad

Answer this question