SpawnLocation is not working?

Hi! I have a short question:

I made a LocalScript, when you touch the part, the SpawnLocation is teleported to the part CFrame (it works); however when I died I spawned at the old SpawnLocation position, is the SpawnLocation not working or am I doing something wrong?


When I touch the part the SpawnLocation CFrame is equal to the part CFrame

But when I died I spawned at the old SpawnLocation position
image

LocalScript
local EMIT_AMOUNT = 80
local Handler = script.Parent
local ParticleEmitter = Handler:FindFirstChild("Explosion")
local Debounce = false

script.Parent.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		if Debounce == false then
			Debounce = true
			local leaderstats = player:FindFirstChild("leaderstats")
			ParticleEmitter:Emit(EMIT_AMOUNT)
			game.Workspace.SpawnLocation.CFrame = script.Parent.CFrame
			leaderstats.Stage.Value += 1
			script:Destroy()
		else
			print("Debounce = true")
		end
	else
		return
	end
end)

Thanks.

3 Likes

It’s because you are teleporting the SpawnLocation only through a local script.

3 Likes

You are setting the Stage value on the client

Client changes don’t replicate to the server so that’s the issue

4 Likes

But that’s what I want: client spawn position is equal to the checkpoint position but when I died I spawned at the old spawn position even if the SpawnLocation is not there, that’s the problem.

2 Likes

Intresting approach to the problem,

wouldn’t it be better to save the value of the part that was last touched and teleport the player there after spawn?

2 Likes

I tried that before but it didn’t work, maybe I should try again.

2 Likes

Teleport in server script, send the value over in a remote event.

script (didn’t test yet)

local spawnposition = workspace.spawnlocation.Cframe
-- if no parts ever touched then function not needed just saying
local function onEvent(player, partPosition)
    spawnposition = partPosition
    player.Character:FindFirstChild("Humanoid").Died:Connect(function()
           local character = player.Character or player.CharacterAdded:Wait()
           character:SetPrimaryPartCframe(spawnposition)
    end)
end)
4 Likes

you could use an ObjectValue

3 Likes

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