I need a simple script that will prohibit people from entering a vehicle’s driver seat unless they’re a specific rank in a group.
For example, if the user isn’t a Sergeant or above in an Army group he may not enter the seat. If you’ve got further questions regarding my request leave it down below, but I believe it’s obvious what I need.
Here’s the script (put it in the seat) but next time don’t ask for entire scripts:
--//Services
local Players = game:GetService("Players")
--//Variables
local Seat = script.Parent
--//Controls
local GroupID = 0000000
--//Functions
Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if not Seat.Occupant then
return
end
local Player = Players:GetPlayerFromCharacter(Seat.Occupant.Parent)
if Player and not Player:IsInGroup(GroupID) then
task.wait(0.05)
Seat.Occupant.Jump = true
end
end)
--//Services
local Players = game:GetService("Players")
--//Variables
local Seat = script.Parent
--//Controls
local GroupID = 0000000
--//Functions
Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if not Seat.Occupant then
return
end
local Player = Players:GetPlayerFromCharacter(Seat.Occupant.Parent)
--//Checks if the player's rank in group is under 50, if so, kick them out of the seat
if Player and Player:GetRankInGroup(GroupID) <= 50 then
task.wait(0.05)
Seat.Occupant.Jump = true
end
end)
local Players = game:GetService("Players")
local Seat = script.Parent
local GroupId = 0
local GroupRank = 0
Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
local Humanoid = Seat.Occupant
if not Humanoid then return end
local Character = Humanoid.Parent
if not Character then return end
local Player = Players:GetPlayerFromCharacter(Character)
if not Player then return end
local SeatWeld = Seat:FindFirstChildOfClass("Weld")
if not SeatWeld then return end
local Success, Result = pcall(function()
return Player:IsInGroup(GroupId)
end)
if Success then
if Result then
local Success2, Result2 = pcall(function()
return Player:GetRankInGroup(GroupId)
end)
if Success2 then
if Result2 then
if Result2 >= GroupRank then
return
end
end
else
warn(Result2)
end
end
else
warn(Result)
end
SeatWeld:Destroy()
end)