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

Why does the script teleport me underground when the pad is above the ground?

Asked by 5 years ago
local db = false
local sword = script.Parent.Parent.Parent.ClassicSword

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        if db == false then
            local spawnpad = script.Parent.Parent.SpawnPad.Position
            db = true
            sword:Clone().Parent = game.Players[hit.Parent.Name].Backpack
            hit.Parent.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(spawnpad))
        end
    end
end)

0
Vector3.new(spawnpad) ??? User#5423 17 — 5y

1 answer

Log in to vote
2
Answered by
Vik954 48
5 years ago

First, Vector3.new(spawnpad) is traduced to Vector3.new(Vector3.new(100, 0, 100)), or what position the spawn pad is at. It should be simply spawnpad, not Vector3.new(spawnpad).

And the second problem is that the HumanoidRootPart's position is in the middle part of the character, so the Y position should be bigger with 3.

This is how the code should be:

local db = false
local sword = script.Parent.Parent.Parent.ClassicSword

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        if db == false then
            local spawnpad = Vector3.new(script.Parent.Parent.SpawnPad.Position.X,Vector3.new(script.Parent.Parent.SpawnPad.Position.Y + 3, Vector3.new(script.Parent.Parent.SpawnPad.Position.Z)
            db = true
            sword:Clone().Parent = game.Players[hit.Parent.Name].Backpack
            hit.Parent.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(spawnpad))
        end
    end
end)
0
.................... User#5423 17 — 5y
Ad

Answer this question