✓ Accepted answer
It seems like your code doesn't run as you expect it to because it executes before any players have joined the server.
What happens is this:
GetPlayers() executes before any players have entered, and returns {}, an empty table
for i,v in pairs(players) sees the empty table and runs 0 times
There are no errors because as far as the script's concerned, it didn't run into any.
Remember that server scripts can run before any players have connected to the server, so it's necessary to check for any players before running any code that involves players.
Here's the code:
local PlayersService = game:GetService("Players")
if #PlayersService:GetPlayers() == 0 then
PlayersService.PlayerAdded:Wait()
end
local players = PlayersService:GetPlayers()
local repstor = game:GetService("ReplicatedStorage")
local gun = repstor.Revolver
for i,v in pairs(players) do
while v.Character == nil do wait() end
local char = v.Character
wait(3)
char:MoveTo(Vector3.new(-45.9, 0.5, 100.2))
end
Also, you could just set the CFrame of the character's HumanoidRootPart to teleport them, which I'd personally recommend, like so:
for i,v in pairs(players) do
while v.Character == nil do wait() end
local HRP = v.Character:WaitForChild("HumanoidRootPart")
wait(3)
HRP.CFrame = CFrame.new(45.9, 0.5, 100.2)
end
In addition, since you specified a certain part to teleport to, you could do this:
HRP.CFrame = PartToTeleportTo.CFrame
This will teleport the players to the center of the part, instead of having to specify the position every time. You could do additional stuff to add offsets so the players wouldn't be inside the part.
2 comments
There's probably no players so :GetPlayers() returned an empty array
What do you mean? Do I need to start a server inside studio? I was going into test mode by the way.