Spawn not working!

return function(player: Player, context: string, part: BasePart)
	local spawnpoint = part.Spawn.Value
	local spawnset = part:findFirstChildWhichIsA("SpawnLocation")
     player.RespawnLocation = spawnset
    print(player.RespawnLocation)
end

This is my code and it sets the spawn but the player dosent spawn their they spawn at the default on, any ideas on how to fix?

is the default spawn enabled? If so then maybe that’s what’s causing the problem.

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.

Its a multiplayer game though so how would that work?

very badly … try teleporting them to the new spot, with a move.

I dont know how I would do that as its a interaction system so I dont think I could keep it that persistent.

I don’t think you really have a choice here. It’s not that bad.

Uh how would I script that then

You could make a module script which returns an item within a table. In this case, it’d be a stud which is located in different parts in the map.

From there you can teleport the player to the location.

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.

Here is an example:

Module script:

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.

I will test them when I can, thanks for helpin.

Also I can send a video showcaseing how it works for you

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.

Sorry I had to go and do somethin

External Media

-------_____

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!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.