How would i make a script to where if you hold e and you respawn you will spawn at the place where you held e. This is my current script: (edit: I defined the spawn and put it an a script since i configured another script and it worked when i touched it and it wasn't a local script.)
local spawn = script.Parent
spawn.ProximityPrompt.Triggered:Connect(function(OnPromtTriggered)
if OnPromtTriggered and OnPromtTriggered.Parent and OnPromtTriggered.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(OnPromtTriggered.Parent)
local checkpointData = game.ServerStorage:FindFirstChild("CheckpointData")
if not checkpointData then
checkpointData = Instance.new("Model", game.ServerStorage)
checkpointData.Name = "CheckpointData"
end
local checkpoint = checkpointData:FindFirstChild(tostring(player.userId))
if not checkpoint then
checkpoint = Instance.new("ObjectValue", checkpointData)
checkpoint.Name = tostring(player.userId)
player.CharacterAdded:connect(function(character)
wait()
character:WaitForChild("HumanoidRootPart").CFrame = game.ServerStorage.CheckpointData[tostring(player.userId)].Value.CFrame + Vector3.new(0, 4, 0)
end)
end
checkpoint.Value = spawn
end
end)
