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
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)
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.
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)