I am trying to make a Seat that only Players I want to be able to sit in,
Is there a way to to that?
I am trying to make a Seat that only Players I want to be able to sit in,
Is there a way to to that?
You could make a “Press E to Sit” gui, it will allow you to have more control over the seat.
I want to use just a basic seat, no GUIs
You can place a script in the seat that will check if the player is allowed to sit
local seat = script.Parent
local AllowedPlayers = {
["wevetments"] = {false},
["Driftyzzz"] = {true}
}
local function OnChildAdded(Child)
if Child.Name == "Weld" and Child:IsA("Weld") then
local Character = Child.Part1.Parent
if AllowedPlayers[Character.Name] then
if AllowedPlayers[Character.Name][1] == false then
seat.Disabled = true
wait(1)
seat.Disabled = false
end
else
seat.Disabled = true
wait(1)
seat.Disabled = false
end
end
end
seat.ChildAdded:Connect(OnChildAdded)
EDIT:
The server can’t make the player jump, probably due to replication.
Didnt seem to work, my friend sat in it.
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)
I misspelled something, this should work now
I’m pretty sure that you can force the player to jump using Humanoid.Jump = true.
With that in mind, you can just make a check once the seat has an occupant with Seat.Occupant.
@Flubberlutsch’s answer is your best solution.
Make a server script that makes the player jump if they aren’t allowed to sit. Along with this, make a localscript that disables the seat so that they can’t sit at all, but will be jumped out if they enable the seat again with exploits.
There isn’t really a way to whitelist users to sit down without forcing them back up. Why, is it crucial that your seat need a whitelist or can you just whitelist the logic that’s established upon players sitting down?
You can disable the seat through the Seat.Disabled property, then include custom logic to sit players down if they are on your list of permitted users.
The code will be similar to this:
local allowed = {1451803}
local players = game:GetService("Players")
local seat = script.Parent
seat.Disabled = true
seat.Touched:Connect(function (hit)
if seat.Occupant then return end
local player = players:GetPlayerFromCharacter(hit.Parent)
for i = 1, #allowed do
if allowed[i] == player.UserId then
local humanoid = player.Character:FindFirstChildWhichIsA("Humanoid")
if humanoid then
seat:Sit(humanoid)
end
break
end
end
end)
Keep in mind, when a player gets up they could fire the touched event again. You will need to add more code to handle this.
You can make a script that set Seat.Disabled = true first , then use v.Touched and check if the player is in the whitelist. If yes, Seat.Disabled = false and Seat:Sit(Humanoid)
Example:
local Seat = script.Parent
local SeatCoodown = 5
Seat.Disabled = true
local WhiteListed = {
["Driftyzzz"] = true,
["Roblox"] = true
}
local IsEnabled = true
Seat.Touched:connect(function(part)
local Humanoid = part.Parent:FindFirstChild("Humanoid")
if IsEnabled and Humanoid and WhiteListed[part.Parent.Name] then
IsEnabled = false
Seat.Disabled = false
Seat:Sit(Humanoid)
end
end)
Seat:GetPropertyChangedSignal("Occupant"):connect(function()
if not Seat.Occupant then
Seat.Disabled = true
wait(SeatCoodown)
IsEnabled = true
end
end)
Of course it just an example, you should use GetPlayerfromcharacter to check if it is the real player in the whitelist (Using UserId would be more secure)
This solution looks good.
Note that UserId would be better (handles username changing). However, it doesn’t make a security difference since Roblox usernames can’t be duplicated. However, I’d still recommend using UserId, unless you’re hard coding the username list.
In that case, you can use Players:GetUserIdFromNameAsync().
Setting Seat.Disabled locally is definitely not the safest method. Anyone with a script injector or memory editor can easily just change Seat.Disabled back to false, allowing them to sit in the seat.
The safest method is server-sided checks, as per the two golden rules:
I know this is an old post, but I want to add this solution in case anyone else is looking for it in the future. Just disable the seat, detect when a character touches it, and if the character meets the sitting requirements, call seat.Sit
Put this script inside of the seat:
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local hum = char:WaitForChild("Humanoid")
hum.Seated:Connect(function(isSeated, seat)
if isSeated and seat == script.Parent and plr.Name ~= "YourName" then
seat.SeatWeld:Destroy()
hum.Sit = false
end
end)
end)
end)