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

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

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

✓ Accepted answer

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.

1 comment

0

ty

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

3 comments

0

what debounce does? im trying to learn scripts

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...

0

I edited it so now its correct I hope

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