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

why does My Script gives out error about "Attempted To Index nil with 'character' " ?

Im Making a Teleporter to My friends airline on roblox. Idk what to say more. heres the script (The Problem will be written down below)

local Teleporter = script.Parent
local Teleporter2 = script.Parent.Parent.Teleporter2
local debounce = false
Teleporter.Touched:Connect(function()
	if debounce == false then
		debounce = true
		game.Players.LocalPlayer.character.Torso.CFrame = CFrame.new(workspace.Teleporter2.Position)
		debounce = false
	end
end)

Now Why does it give out error? Cuz I have been doing the same before (In another way of teleporting).

Please help

2 comments

0

Is this a serverscript?

0

@Zethuslmam yes. i attempted to Put it in localscript. No errors but It dont teleport you

2 answers

✓ Accepted answer

You should be handling this on the server, which means we cant use LocalPlayer. Try this:

local Teleport1 = -- Put the first Teleporter here.
local Teleport2 = -- Put the second Teleporter here.
local Deb = false;

Teleport1.Touched:Connect(function(Hit)
     local Player = game.Players:GetPlayerFromCharacter(Hit.Parent);
     if Player and Deb == false then
          Deb = true;
          Player.Character:MoveTo(Teleport2.Position);
          Deb = false;
     end
end)

1 comment

0

thanks

Its in Localscript. I attempted it but it says no errors but dont works

local Teleporter = script.Parent
local Teleporter2 = script.Parent.Parent.Teleporter2
local debounce = false
Teleporter2.Touched:Connect(function()
	if debounce == false then
		debounce = true
		game.Players.LocalPlayer.Character.Torso.CFrame = CFrame.new(workspace.Teleporter.Position)
		debounce = false
	end
end)

.,_,.

5 comments

0

You can't have a localscript in the workspace

0

Try what I did.

0

Do what ZethusImam said

0

Do what ZethusImam said

0

why did that post twice?

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