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

HumanoidRootPart Teleporting Not working HELP?

so when you touch the lava instead of teleporting you to the correct position it teleports you to anything from 1,1,1 to 0,0,0

I cheaked with print spawnposition gives me the right value its something like 256,20ish, 0 and also does hidden value idk whats going wrong

local PlayerService = game:GetService("Players")

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:findFirstChild("Humanoid") then
		local HiddenValue = PlayerService:FindFirstChild(hit.Parent.Name).HiddenValues.CurrentLevel.Value
		local SpawnPosition = game.Workspace.Spawns:FindFirstChild(HiddenValue).Position
		hit.Parent.HumanoidRootPart.Position = Vector3.new(game.Workspace.Spawns:FindFirstChild(HiddenValue).Position)
	end
end)

1 answer

✓ Accepted answer

If you want to teleport a player to this location, you might want to try using CFrame instead of Position. Also, just to be safe, I always work with the head of a player, instead of messing with its HumanoidRootPart. This means you might need to add 1 or 2 to the y-value of your location.

local PlayerService = game:GetService("Players")

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:findFirstChild("Humanoid") then
        local HiddenValue = PlayerService:FindFirstChild(hit.Parent.Name).HiddenValues.CurrentLevel.Value
        local SpawnPosition = game.Workspace.Spawns:FindFirstChild(HiddenValue)
        hit.Parent.Head.CFrame = CFrame.new(SpawnPosition.Position)
    end
end)

Let me know if this fixed anything.

5 comments

0

thanks it worked and also im a idiot cuz i know what CFrame is but i started learning scripting like 2 week ago

0

No problem! Glad I could make it work

0

Please accept the answer rather then renaming the title

0

Oh I've just noticed that as well XD

0

k done that dident realise

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