i realized i put everything in a folder so i need to fix those. just give me a min
remember to locate the seat parts inside the Seat
table
wdym by that. The code does work fine for me now but I just want to know bec maybe that will fix it from me still loading outside but only for like few seconds
oh its just when i said this earlier but im assuming you know how tables work. also idk why ur still outside for a little bit maybe just cuz ur character is loading
I can just send a video so you know what im talking about. Just give me a few seconds
Probably cause it teleports before animate script can play sit animation
is there away to fix that because it does not sit me after
yeah u can make the tp script wait like 0.1 seconds or something but that would make it so u see outside the map for a tiny amount of time
how would i do that. sorry im not good at coding at all
its alright just put wait(0.1)
at the beginning of the script
it works. I just realized if you go to actual game it does not even show it bec of how slow it takes to load game like when i join im already spawned there seated
and sorry to ask. I need to ask 1 more thing since it does take a second before sitting i want it to be where I cant move my chracter till the chracter sits so It does not interfear with any bugs if they do happen in future
also sorry i keep asking so many questions when i join in R6 mode it does not sit me and only sits me if i reset my chracter. I hope im not asking too much
ok so thats probably because for some reason roblox has a 5 second wait time for each person to sit in the same seat. also i dont mind answering ur questions
in studio it works but in game it does not. so idk how to fix that. but R15 works fine. but my game runs in R6
im not sure what the issue is but ill try to find a solution
here ya go. ive gotta go to bed but ill answer questions tomorrow if u have any
wait()
local Seats = {
game.Workspace.Couch1.Seat1,
game.Workspace.Couch1.Seat2,
}
local character = script.Parent
local hrp = character:WaitForChild("HumanoidRootPart")
function SeatOccupied(Seat)
local occupant = Seat:FindFirstChild("SeatWeld")
return occupant
end
function teleportToSeat()
local AvailableSeats = {}
for _,v in pairs(Seats) do
if not SeatOccupied(v) then
table.insert(AvailableSeats,v)
end
end
local PickedSeat
if #AvailableSeats > 0 then
PickedSeat = AvailableSeats[math.random(1,#AvailableSeats)]
hrp.CFrame = PickedSeat.CFrame
else
PickedSeat = Seats[math.random(1,#Seats)]
hrp.CFrame = PickedSeat.CFrame * CFrame.new(0,SeatOccupied(PickedSeat).Parent.PrimaryPart.Size.Y + 1 + hrp.Size.Y,0)
end
end
teleportToSeat()
still does not sit me when i join the game but respawning does let me sit
You need to make a server script.
I made a script for you, to make it work you need to make a folder inside workspace called βSeatsβ and place a few seats inside. You can mess around with the script and customize it to your liking.
task.spawn(function()
task.wait(1) -- Giving server time to load.
Seats = workspace:WaitForChild('Seats'):GetChildren()
-- Also make an attribute in the seat called 'Available'.
end)
local Debris = game:GetService('Debris')
function CreateItem(item,parent)
local Item = Instance.new(item,parent)
return Item
end
function SpawnSeat(Char)
for _,v in ipairs(Seats) do
if v:IsA('Seat') and v:GetAttribute('Available') == true then
local AvailbleS = v:GetAttribute('Available')
Char.PrimaryPart.CFrame = v.CFrame
AvailbleS = false
local Weld = CreateItem('Weld',v)
Weld.Part0 = v
Weld.Part1 = Char.PrimaryPart
task.spawn(function()
if Weld then
Debris:AddItem(Weld,0.4)
end
end)
v.Name = game.Players:GetPlayerFromCharacter(Char).Name..' seat'
if v.Name == game.Players:GetPlayerFromCharacter(Char).Name..' seat' then
break
end
end
end
end
function PlayerAdded(Player)
Player.CharacterAdded:Connect(function(Character)
task.wait(1)
SpawnSeat(Character)
local Humanoid = Character:WaitForChild('Humanoid')
Humanoid.JumpPower = 0 -- U can anchor the HumRootPart if youd rather want that
wait(1)
local Seat = workspace.Seats:FindFirstChildWhichIsA('Seat'):Clone() -- creating a 'seat' on the characters head
Seat.CFrame = Character.Head.CFrame + Vector3.new(0,2,0)
Seat.Anchored = true
Seat.Transparency = 1
Seat.Parent = workspace.Seats
Seat.Name = Player.Name..'CustomSeat'
end)
end
game.Players.PlayerAdded:Connect(PlayerAdded) -- Runs when player joins
game.Players.PlayerRemoving:Connect(function(Player) -- when player leaves the seat will be available again
for _,v in pairs(Seats) do
if v.Name == Player.Name..' seat' then
local a = v:GetAttribute('Available')
a = true
v.Name = 'Seat'
end
end
end)