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

Whats wrong with my teleport script? How i need to change it

Asked by 3 years ago

I dunno what to do with my teleport script because it dont teleporting player when touched. Output says " Workspace.Portal.PortalPart.Script:5: attempt to index nil with 'Character' ".

This is a script:

local scndChck = game.Workspace.SecondCheck

local function touch(hit)
    local player = game.Players.LocalPlayer
    player.Character.HumanoidRootPart.CFrame = CFrame.new(scndChck.Position.X,scndChck.Position.Y + 5,scndChck.Position.Z)
end

script.Parent.Touched:Connect(touch)

2 answers

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

Hello, you got messed up that CFrame set on line 7. I rewrited the script in shorter way and also fixed the code, here it is:

local scndChck = game.Workspace.SecondCheck

script.Parent.Touched:Connect(function(part)
    local players = game:GetService("Players")
    if part.Parent:FindFirstChild("Humanoid") then
        local plr = players:GetPlayerFromCharacter(part.Parent)
        plr.Character.HumanoidRootPart.CFrame = scndChck.CFrame + Vector3.new(0,5,0)
    end
end)

I wish you good luck in future scripting, have a nice day and I hope this helped.

0
ty SashaPro336 47 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago
local debounce = true

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        if debounce == true then
            debounce = false
            hit.Parent.HumanoidRootPart.Position = Vector3.new(0,0,20) 
            debounce = true
        end
    end
end)

probs dont need debounce

0
what debounce does? im trying to learn scripts SashaPro336 47 — 3y
0
https://developer.roblox.com/en-us/articles/Debounce I just realized I didn't even use it correctly here lol, but basically it doesn't allow the script to run if its false. I am also explaining it wrong so just check out the link... FantasticFrontierGuy 33 — 3y
0
I edited it so now its correct I hope FantasticFrontierGuy 33 — 3y

Answer this question