Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

HumanoidRootPart Teleporting Not working HELP?

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

0
thanks it worked and also im a idiot cuz i know what CFrame is but i started learning scripting like 2 week ago LordOfSour 9 — 4y
0
No problem! Glad I could make it work Dylan011444 59 — 4y
0
Please accept the answer rather then renaming the title SoftlockedUnderZero 668 — 4y
0
Oh I've just noticed that as well XD Dylan011444 59 — 4y
0
k done that dident realise LordOfSour 9 — 4y
Ad

Answer this question