Spawn points have an enable on them. To move spawn spots just make that false on the old one and make the new one true. You can’t just tell it what spawn point to go to like you’re doing here.
Need to know a few things here… What is the “trigger” that they should go to a different spawn spot.
Is it score or just the fact they died? Is this like an obby where they spawn to the last progressive spawn spot they reached? Does the different spawn spots go in an order or could they be random or do you want to set what spawn they go to?
I’m assuming you have many spawn spots, is that the case?
I really hope you say like a obby. The answer would easy then.
table = {
Spawn_1 = {
Obj = game.Workspace.SpawnName, -- your spawn
Name = 'Spawn1'
},
Spawn_2 = {
Obj = game.Workspace.SpawnName2,
Name = 'Spawn2'
},
};
return table
Script:
local HRoot = game.Players.Localplayer.Character.HumanoidRootPart
local mod = require(modulescriptinstance)
function TeleportSpawn(SpawnName)
for a,b in pairs(mod) do
if b.Name == SpawnName then
HRoot.CFrame = b.Obj.CFrame
end
end
end)
Well no reply so I’ll go with the hardcore version.
local DataStoreService = game:GetService("DataStoreService")
local playerDataStore = DataStoreService:GetDataStore("PlayerSpawnData")
local function getKey(player)
return "SpawnIndex_" .. player.UserId
end
local spawns = {
{ x = 80.929, y = 0.5, z = 0 },
{ x = 119.826, y = 0.5, z = 0 },
{ x = 160.752, y = 0.5, z = 0 },
{ x = 217.541, y = 0.5, z = 0 },
}
function moveToSpawn(player, index)
local location = spawns[index]
if location then
player.Character:SetPrimaryPartCFrame(CFrame.new(location.x, location.y, location.z))
end
end
game.Players.PlayerAdded:Connect(function(player)
local success, index = pcall(function()
return playerDataStore:GetAsync(getKey(player))
end)
if success then
moveToSpawn(player, index or 1)
else
warn("Failed to retrieve spawn index for player:", player.Name)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local index = player:WaitForChild("SpawnIndex").Value
local success, err = pcall(function()
playerDataStore:SetAsync(getKey(player), index)
end)
if not success then
warn("Failed to save spawn index for player:", player.Name, "-", err)
end
end)
This version uses a DataStore to hold the index for the respawn spot. Them are locations of spawn tiles with the enabled set to false. While you still have the org spawn spot set to true.
Also, I didn’t test that … It might just blow up. Think I got it however.
If this is like an OBBY there is an example one in the studio doing this perfectly, without a DataStore.
Just hit new and click on that obby to study it.
Would have been better if you had just answered my question. There are many ways to do something like this. I gave you the blow your brains out version that works in any possible case.
Looks like you have everything set up and you just need a way to get that information on respawn to set it in motion. So just add a datastore to that, set it when they change spawn and read the datastore to send them off to it when they respawn. Ultimate Dimer is using a direct part to part move. I’m setting x,y,z … just pick one. You have both ways to get to them there posted here. GL!