I’m making a custom random spawning system for practicing purposes, but it doesn’t work.
Code in a ServerScript, stored in ServerScriptService.
local collectionService = game:GetService("CollectionService")
local spawnLocationsTag = collectionService:GetTagged("SpawnLocations")
-- The spawnLocationsTag includes 9 Parts, representing spawn locations. All of them are named 'SpawnLocation1', 'SpawnLocation2', 'SpawnLocation3', 'SpawnLocation4', and so on.
print("Test") -- Prints successfully
game.Players.PlayerAdded:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local spawnLocationValue = math.random(1, 9)
print("Test") -- Prints successfully
print(spawnLocationValue) -- Prints successfully
for i, spawnLocation in (spawnLocationsTag) do
print("Test") -- Prints successfully
if spawnLocation.Name == "SpawnLocation" .. spawnLocationValue then
humanoidRootPart.CFrame = spawnLocation.CFrame + Vector3.new(0, 10, 0)
print("Test") -- Prints successfully
end
end
end)
All of your prints are named ‘Test’, have you ensured that the correct ones are being printed and it’s not just the loop-print being repeated several times?
It would be good to have the client do the teleporting. Have the server send a remote event to the new position. It might break if the client is super laggy.