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

Script that's supposed to seat players puts multiple people in one seat?

Asked by
Avoxea 48
5 years ago

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!

01script.Parent.MouseButton1Click: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.seat1.Occupied.Value == false then
10        player.Character.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(1.3, 0.5, 9.4))
11        noRset()
12        game.Workspace.seat1.Occupied.Value = true
13    elseif game.Workspace.seat2.Occupied.Value == false then
14        player.Character.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(8.4, 0.5, 9.8))
15        noRset()
View all 26 lines...

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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

01local updateValueRE = game.ReplicatedStorage.UpdateValueRemoteEvent
02local seats = {}
03local seat_value = 1
04 
05while 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)
View all 30 lines...

**in local script ** make sure the script is paranted to the pressable GUI: AKA a button

1script.Parent.MouseButton1Click:Connect(function()
2    local updateValueRE = game.ReplicatedStorage.UpdateValueRemoteEvent
3    updateValueRE:FireServer()
4end)

Now this is just an example, but you can do it differently

0
i don't understand what any of that code does Avoxea 48 — 5y
Ad
Log in to vote
0
Answered by
Avoxea 48
5 years ago

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 !!

Answer this question