Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My teleport to stage on death script isn't working. Any help?

I am not trying to make a checkpoint, just a setting when you enable it, you teleport to your stage. There is a leaderboard for like stage 1, etc... I added this in my starter GUI, so when you enable the button, you automatically get sent to the stage when you die. But it isn't doing anything, even when enabled. Please help?

while true do
	wait(0.01)
	if script.Parent.Value == true then
		
	game:GetService('Players').PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").Died:Connect(function()

	local check = player.Parent:FindFirstChild("Humanoid") --Find the human that touched the button


		local user = game.Players:GetPlayerFromCharacter(player) 
		local stats = user:findFirstChild("leaderstats") 

		if stats ~= nil then 
			local S = stats:findFirstChild("Stage").Value
		    if S == 1 then
			 user.Character.HumanoidRootPart.CFrame = CFrame.new(66, 5, -167)
		end
		if S == 2 then
			 user.Character.HumanoidRootPart.CFrame = CFrame.new(66, 33, -361)
		end
		if S == 3 then
			 user.Character.HumanoidRootPart.CFrame = CFrame.new(65, 44, -434)
		end
		if S == 4 then
			 user.Character.HumanoidRootPart.CFrame = CFrame.new(66, 44, -495)
		end
		if S == 5 then
			 user.Character.HumanoidRootPart.CFrame = CFrame.new(66, 44, -562)
		end
		if S == 6 then
			 user.Character.HumanoidRootPart.CFrame = CFrame.new(66, 44, -618)
		end
		if S == 7 then
			 user.Character.HumanoidRootPart.CFrame = CFrame.new(66, 47, -683)
		end
		if S == 8 then
			 user.Character.HumanoidRootPart.CFrame = CFrame.new(66, 44, -734)
		end
		if S == 9 then
			 user.Character.HumanoidRootPart.CFrame = CFrame.new(64, 80, -799)
		end
		if S == 10 then
			 user.Character.HumanoidRootPart.CFrame = CFrame.new(64, 80, -866)
		end
		if S == 11 then
			 user.Character.HumanoidRootPart.CFrame = CFrame.new(64, 80, -921)
		end
		if S == 12 then
			 user.Character.HumanoidRootPart.CFrame = CFrame.new(59, 80, -981)
		end
		if S == 13 then
			 user.Character.HumanoidRootPart.CFrame = CFrame.new(59, 80, -1045)
		end
		if S == 14 then
			 user.Character.HumanoidRootPart.CFrame = CFrame.new(59, 80, -1089)
		end
		if S == 15 then
			 user.Character.HumanoidRootPart.CFrame = CFrame.new(59, 80, -1165)
		end
		if S == 16 then
			 user.Character.HumanoidRootPart.CFrame = CFrame.new(59, 80, -1216)
		end
		if S == 17 then
			 user.Character.HumanoidRootPart.CFrame = CFrame.new(59, 80, -1235)
		end
		if S == 18 then
			 user.Character.HumanoidRootPart.CFrame = CFrame.new(59, 80, -1254)
		end
		if S == 19 then
			 user.Character.HumanoidRootPart.CFrame = CFrame.new(59, 80, -1339)
		end
		if S == 20 then
			 user.Character.HumanoidRootPart.CFrame = CFrame.new(59, 80, -1461)
		end
		if S == 21 then
			 user.Character.HumanoidRootPart.CFrame = CFrame.new(59, 80, -1533)
		end
		if S == 22 then
			 user.Character.HumanoidRootPart.CFrame = CFrame.new(59, 96, -1565)
		end
		if S == 23 then
			 user.Character.HumanoidRootPart.CFrame = CFrame.new(59, 96, -1626)
		end
		
			wait() 

	


	end

		end)
	end)
end)
	end
	end

No errors in f9, or Roblox studio, even the script "Go to script Error". Edit: This is a script, not a local. Also, it is located in StarterGui.frame.button etc...

1 comment

0

you dont put it in a while loop and you dont do it completely on the server, you have to handle the deaths in a local script and then fire to the server telling the player has died

2 answers

While writing this script, I'm assuming that the stages are named by what stage they are (Stage 1 is named 1, stage 2 is named 2, etc.)

game.Players.PlayerAdded:Connect(function(user)
     local stats = user:findFirstChild("leaderstats")
     if stats ~= nil then
          S = stats:findFirstChild("Stage")
     end

     user.CharacterAdded:Connect(function(char)
          local stage = game.Workspace:FindFirstChild(S.Value)
          char.HumanoidRootPart.Position = stage.Position + Vector3.new(0,10,0)
     end)
end)

BTW, this script goes in the ServerScriptService in case you didn't know. Also, this script WILL NOT WORK if you do not name your stages the value that S should be. If stage 1 is named 'Stage 1' or 'Stage1' or 'S1' the script won't work. Stage 1 needs to be named '1'. When I'm saying it needs to be named that, I mean the part in the workspace needs to be named that. This should work, and I hope it answers your question

Just saying, that is a lot more code than needed. Use SpawnLocations and inside each one add this code:

local players = game:GetService("Players")

script.Parent.Touched:Connect(function(part)
	if part.Parent:FindFirstChild("Humanoid") then
		local player = player:GetPlayerFromCharacter(part.Parent)
		player.RespawnLocation = script.Parent
	end
end)

The player has a value called RespawnLocation which decides where it spawns. At the beginning of the game set it to the first spawn location.

Hope this helped.

1 comment

0

I need it to happen if the button is enabled.

This discussion is preserved as it was. New answers, comments, and votes are closed.