The below script is intended to put players in a seat if it is not already occupied. I have boolValues inside their corresponding parts, however when I try to test this it teleports me and someone else to seat1. Please help!
01 | script.Parent.MouseButton 1 Click:Connect( function () |
02 | player = game.Players.LocalPlayer |
03 | --Makes it so the player can't reset once boarded |
04 | local function noRset() |
05 | noReset = game.Workspace.NoReset:Clone() |
06 | noReset.Parent = player:WaitForChild( "PlayerGui" ) |
07 | end |
08 | print ( "hi" ) |
09 | if game.Workspace.seat 1. Occupied.Value = = false then |
10 | player.Character.HumanoidRootPart.CFrame = CFrame.new(Vector 3. new( 1.3 , 0.5 , 9.4 )) |
11 | noRset() |
12 | game.Workspace.seat 1. Occupied.Value = true |
13 | elseif game.Workspace.seat 2. Occupied.Value = = false then |
14 | player.Character.HumanoidRootPart.CFrame = CFrame.new(Vector 3. new( 8.4 , 0.5 , 9.8 )) |
15 | noRset() |
well, you doing it in a LocalScritpt, therefore, the seat.Occupied
property only changes on one player's screen, but not other players. you would need to use remote events to update the seat.Occupied
ex: **step 1: put remote event somewhere in replicated storage
step 2: put a server script somewhere in ServerScriptService
step 3: put a LocalScript somewhere, where it will be cloned to be a descendant of player object**
In Server Script
01 | local updateValueRE = game.ReplicatedStorage.UpdateValueRemoteEvent |
02 | local seats = { } |
03 | local seat_value = 1 |
04 |
05 | while true do |
06 | local seat = workspace [ tostring ( "seat" ..seat_value) ] |
07 | if not seat then |
08 | break |
09 | end |
10 | seat_value = seat_value+ 1 |
11 |
12 | if seat.Classname:lower() = = "seat" then |
13 | table.insert(seats,#seats+ 1 ,seat) |
14 | end |
15 | wait( 0.1 ) |
**in local script ** make sure the script is paranted to the pressable GUI: AKA a button
1 | script.Parent.MouseButton 1 Click:Connect( function () |
2 | local updateValueRE = game.ReplicatedStorage.UpdateValueRemoteEvent |
3 | updateValueRE:FireServer() |
4 | end ) |
Now this is just an example, but you can do it differently
okay i saw that the above person mentioned an "occupant" property that i didn't notice so i incorporated that into my script by adding an "and not game.Workspace.seat1.Occupant" after the boolValue check. thanks !!