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

Howcome this script does not teleport the player to the spawn once they have hit the object?

function Touch(hit)
	local Tor = hit.Parent:FindFirstChild("Torso")
	local Spawn = game.Workspace.Stages:FindFirstChild("1")
	local hum = hit.Parent:FindFirstChild("Humanoid")
	
	if Tor then
	if hum then
	hum.WalkSpeed = 16
	Tor.Position = Spawn.Position
	end
	end
	end
	
script.Parent.Touched:Connect(Touch)

2 answers

✓ Accepted answer

I guess you should change the CFrame of the Humanoid Root Part to the spawn's CFrame like this:

function Touch(hit)
	local Spawn = game.Workspace.Stages:FindFirstChild("1")
	local parent = hit.Parent --Getting the parent of the part that touched the brick
	if game.Players:GetPlayerFromCharacter(parent) then --Checking if the parent is a player's character
		parent.HumanoidRootPart.CFrame = Spawn.CFrame + Vector3.new(0,5,0) --Changin the humanoid root part CFrame to the spawn CFrame plus 5 studs up so the player doesnt get stuck on the floor
	end
end

script.Parent.Touched:Connect(Touch)

2 comments

0

Or use :SetPrimaryPartCFrame().

0

I get what you did, but howcome your method would work but not mine? Don't they do the same thing?

script.Parent.Touched:Connect(function(h) local hum = h.Parent:FindFirstChild('Humanoid') if hum ~= nil then h.Parent.HumanoidRootPart.CFrame = CFrame.new(workspace.Stages.StageOne.Position) end end)

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