Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Making players spawn in seats, them not allowing then to jump out?

I'm making a game but I don't know what functions I would use to make the table seats spawn by the # of players in the game, then put all the players into the seats and make it so they can't move. (The game that i'm making involves game rounds, so i want the seats to match the number of players, and then make the players spawn in the seats when the round starts. But how would I do that...) Help? NOT ASKING FOR SCRIPTS, ASKING FOR HELP TO LEAD ME INT THE RIGHT DIRECTION.

3 comments

0

Not a request site!

0

incapaz seems to have not understood the post, I downvoted his moderation requests.

0

They just recently edited it, buffoon^

3 answers

✓ Accepted answer

I believe what you're looking for would look something like this:

AllPlayers = {}
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Seat = ReplicatedStorage:FindFirstChild('Seat') --hypothetically if you're holding the model of the chair in the RS
local Players = game:GetService("Players")
for _,v in pairs(Players:GetPlayers()) do
	table.insert(AllPlayers, v)
	for i = 1,#AllPlayers do
	local clone = Seat:Clone()
	clone.Name ='clone';
	clone.Parent = workspace
	clone:MoveTo(Vector3.new(0,0,0)) -- wherever you want the chairs positioned
	v.Character.Humanoid:MoveTo(workspace:FindFirstChild('clone').Position)
	end
end

clone.Touched:connect(function(hit)
	local Humanoid = hit.Parent:WaitForChild("Humanoid")
	Humanoid.JumpPower = 0;
	wait(180) -- however long the round is
	Humanoid.JumpPower = 50
end)

Now, this is by no means exactly what you're looking for since it's only hypothetical, but the logic should be the same.

Some links to help you: http://wiki.roblox.com/index.php?title=MoveTo http://wiki.roblox.com/index.php?title=API:Class/Humanoid/JumpPower http://wiki.roblox.com/index.php?title=Global_namespace/Basic_functions#pairs https://wiki.roblox.com/index.php?title=API:Class/BasePart/Touched

Oh and I forgot, you would probably want to use a for loop to offset the model's properly.

2 comments

0

Would the script be able to run in Workspace?

0

Yes, if the game is FilteringEnabled, make sure its inside a serverscript.

In terms of making it so the Player's can't jump you can put their WalkSpeed and JumpPower to 0. Then teleport them onto a seat and they will not be able to get off it. And now in terms of placing the seats, you could pre-place them around the table or take a more complicated approach.

If pre-placing them you would just need to label them 1,# of max players and place players in that order.

If you want the complicated way you could take the maximum number of players, and the X,Z dimensions of the table as well as the size of one seat.

Please note I just came up with this in my and have in no way tested it, so my logic may be flawed

Say the X size of the table is 100, the Z is 50, the seat width is 10, and you have 8 players.

In terms of figuring out the maximum number of seats...

You would likely want to place Players on the shorter side first. So take your Z and divide it by your seat width, you will get 5, that's 5 seats you can fit, but let's say you don't want all the seats directly next to each other, you want a buffer of 2.5 so therefore...

Each seat width is not 2.5 (left) + 10 + 2.5 (right) so 15

Now 50/15 is 3.33 repeating so we round down to 3. So you can fit 3 seats on the short side.

Going onto the long side, you would follow the same direction as the short side. Take the X and divide it by 15. We get 6.66 repeating. We will round that down to 6. So you can fit 6 seats on the long side.

So in total you can fit 3 x 2 sides + 6 * 2 sides = 18 players at the table.

That's great but we only have 8 players. So lets say your max players is 10.

In terms of accounting for player numbers and positioning of seats...

You would figure out how many you want on each side by doing 8/10 = 0.8 or 80% of the seats to be filled.

Starting with the short side which can fit 3 players per side, we would do 3 * 0.8 = 2.4, round down to 2 players per short side. Now we subtract 4 players from 8 to get 4 players left.

Now we repeat for the long side, 4/10 = 0.4 or 40%.

0.4 * 6 seats per long side = 2 per side.

Now with placement and continuing with the long side, to space out the seats you would do 100 - 15 * 2 seats = 70 / 2 seats = 35, so when placing them you would move down 35 + 7.5, place a seat (7.5 is 15/2 or the center of the seat position), move down 35+7.5 + 7.5 then place a seat.

You would do the exact same with the short side.

1 comment

0

Thanks, but how would I make the seats spawn before the round matching the number of players in the server, and the whe the round starts, make them teleport into the seats?

This discussion is preserved as it was. New answers, comments, and votes are closed.