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

Big problem in my game. (makes everyone teleport to my stage) ?

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
wait(0.1)
script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        hit.Parent.HumanoidRootPart.CFrame = game.Workspace:FindFirstChild(tostring(player.leaderstats.Stage.Value)).CC.CFrame
       
   end
end)
end)
end)

this for some reason makes every player teleport to the stage i am at when dying and touching one of these parts with this script in it ^^

Please help!

2 answers

✓ Accepted answer
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("HumanoidRootPart") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
hit.Parent.HumanoidRootPart.CFrame = CFrame.new(game.Workspace:FindFirstChild(tostring(player.leaderstats.Stage.Value)).CC.Position)
end
end)

this will get the player from the touch (never use the characteradded function when you want the player who touched it) and teleports them to the place they should be on

1 comment

0

Thanks alot!

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		wait(0.1)
		script.Parent.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid") then
				if hit.Parent.Name == character.Name then
					hit.Parent.HumanoidRootPart.CFrame = game.Workspace:FindFirstChild(tostring(player.leaderstats.Stage.Value)).CC.CFrame
				end
			end
		end)
	end)
end)

This should work, the problem with your script was that it wasent checking who touched it, because that touched event is running for everyone. instead you have to check if the person that wants to teleport was the person that actually touched it.

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