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

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

Asked by 4 years ago

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)

01local Teleporter = script.Parent
02local Teleporter2 = script.Parent.Parent.Teleporter2
03local debounce = false
04Teleporter.Touched:Connect(function()
05    if debounce == false then
06        debounce = true
07        game.Players.LocalPlayer.character.Torso.CFrame = CFrame.new(workspace.Teleporter2.Position)
08        debounce = false
09    end
10end)

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

Please help

0
Is this a serverscript? ACHRONlX 255 — 4y
0
@Zethuslmam yes. i attempted to Put it in localscript. No errors but It dont teleport you HKprogram 48 — 4y

2 answers

Log in to vote
0
Answered by
ACHRONlX 255 Moderation Voter
4 years ago

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

01local Teleport1 = -- Put the first Teleporter here.
02local Teleport2 = -- Put the second Teleporter here.
03local Deb = false;
04 
05Teleport1.Touched:Connect(function(Hit)
06     local Player = game.Players:GetPlayerFromCharacter(Hit.Parent);
07     if Player and Deb == false then
08          Deb = true;
09          Player.Character:MoveTo(Teleport2.Position);
10          Deb = false;
11     end
12end)
0
thanks HKprogram 48 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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

01local Teleporter = script.Parent
02local Teleporter2 = script.Parent.Parent.Teleporter2
03local debounce = false
04Teleporter2.Touched:Connect(function()
05    if debounce == false then
06        debounce = true
07        game.Players.LocalPlayer.Character.Torso.CFrame = CFrame.new(workspace.Teleporter.Position)
08        debounce = false
09    end
10end)

.,_,.

0
You can't have a localscript in the workspace Pupppy44 671 — 4y
0
Try what I did. ACHRONlX 255 — 4y
0
Do what ZethusImam said ThatDevTim 188 — 4y
0
Do what ZethusImam said ThatDevTim 188 — 4y
0
why did that post twice? ThatDevTim 188 — 4y

Answer this question