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

Why is it teleporting player to wrong position?

Asked by 3 years ago

I want to teleport the player to a position using SetPrimaryPartCFrame, but it teleports me above the roof. Though for a second it teleports me to the right place but a second later teleport me above? I was using :MoveTo and it was the same but people said SetPrimaryPartCFrame would work but its still the same. Heres the code im using: (this is a local script)

local stage = game.workspace.Stages:FindFirstChild(game.Players.LocalPlayer:WaitForChild("le
aderstats").Stage.Value)
local UserInputService = game:GetService("UserInputService")

local function onInputBegan(input,gameProcessed)
    if input.UserInputType == Enum.UserInputType.Keyboard then
        local keyPressed = input.KeyCode
        if keyPressed == Enum.KeyCode.Space then
            game.ReplicatedStorage.RespawnEvent:FireServer()
            script.Parent:SetPrimaryPartCFrame(CFrame.new(stage.Position))

            end
        end
    end

UserInputService.InputBegan:connect(onInputBegan)

This is the RespawnEvent script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = ReplicatedStorage:WaitForChild("RespawnEvent")


local function Respawn(player)
    player:LoadCharacter()

end


remoteEvent.OnServerEvent:Connect(Respawn)

Also tried this, didnt work:

local stage = game.workspace.Stages:FindFirstChild(game.Players.LocalPlayer:WaitForChild("le
aderstats").Stage.Value)
local UserInputService = game:GetService("UserInputService")

local function onInputBegan(input,gameProcessed)
    if input.UserInputType == Enum.UserInputType.Keyboard then
        local keyPressed = input.KeyCode
        if keyPressed == Enum.KeyCode.Space then
            game.ReplicatedStorage.RespawnEvent:FireServer()
            script.Parent:SetPrimaryPartCFrame(CFrame.new(Vector3.new(stage.Po
sition)))

            end
        end
    end

UserInputService.InputBegan:connect(onInputBegan)

I also tried this: and it didnt even print "teleporting" and did not teleport me, why this?

local stage = game.workspace.Stages:FindFirstChild(game.Players.LocalPlayer:WaitForChild("leaderstats").Stage.Value)
local UserInputService = game:GetService("UserInputService")

local function onInputBegan(input,gameProcessed)
    if input.UserInputType == Enum.UserInputType.Keyboard then
        local keyPressed = input.KeyCode
        if keyPressed == Enum.KeyCode.Space then
            game.ReplicatedStorage.RespawnEvent:FireServer()
            wait (1)
            print "teleporting"
            script.Parent:SetPrimaryPartCFrame(CFrame.new(stage.Position))

            end
        end
    end

UserInputService.InputBegan:connect(onInputBegan)

Tried this:

local stage = game.workspace.Stages:FindFirstChild(game.Players.LocalPlayer:WaitForChild("le
aderstats").Stage.Value).Position
local UserInputService = game:GetService("UserInputService")

local function onInputBegan(input,gameProcessed)
    if input.UserInputType == Enum.UserInputType.Keyboard then
        local keyPressed = input.KeyCode
        if keyPressed == Enum.KeyCode.Space then
            game.ReplicatedStorage.RespawnEvent:FireServer()
            script.Parent:SetPrimaryPartCFrame(CFrame.new(stage))

            end
        end
    end

1 answer

Log in to vote
0
Answered by 3 years ago

If stage path is a Vector3 value try this:

local stage = game.workspace.Stages:FindFirstChild(game.Players.LocalPlayer):WaitForChild("leaderstats").Stage.Value
    local UserInputService = game:GetService("UserInputService")

    local function onInputBegan(input,gameProcessed)
        if input.UserInputType == Enum.UserInputType.Keyboard then
            local keyPressed = input.KeyCode
            if keyPressed == Enum.KeyCode.Space then
                game.Players.LocalPlayer.Character:MoveTo(stage.Position)
                game.ReplicatedStorage.RespawnEvent:FireServer()
            end
        end
    end

    UserInputService.InputBegan:Connect(onInputBegan)

If not, modify the path stage to be a Vector3 value, according to the desired spawn position.

Hope this helped.

Have an excellent night

1
Thanks! Its working now 123titiago 3 — 3y
0
You're welcome! destinid10_2 50 — 3y
Ad

Answer this question