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

Why isn't this script working ? I putted it inside an Script

Asked by
Komas19 34
3 years ago

Im trying to make an zone system using teleport pads It's in an Script it gives me : Workspace.Zones.Portal1.TeleportPads.Part1.Script:7: attempt to index nil with 'leaderstats'

--By zamsongod.
--Unlike Clockwork's teleporter, this one teleports ANYTHING not just people!
--Make sure the Part to teleport to is in the same group as this Part.
--Feel FREE to Copy, Abuse and Covet!
local player = game:GetService("Players")
local plr = player.LocalPlayer
local leaderstats = plr.leaderstats
local Teleport = "Part2" --Put the name of the Part between the ""s.
function Touch(hit) --Indicates that the Part has been Touched.
    if leaderstats.Prestige.Value >= 1 then
        if script.Parent.Locked == false and script.Parent.Parent:findFirstChild(Teleport).Locked == false then script.Parent.Locked = true script.Parent.Parent:findFirstChild(Teleport).Locked = true --Checks Debounce.
            local Pos = script.Parent.Parent:findFirstChild(Teleport) --Gets the Part to teleport to.
            hit.Parent:moveTo(Pos.Position) wait(1) script.Parent.Locked = false script.Parent.Parent:findFirstChild(Teleport).Locked = false end end --Takes you there and Ends the Function.
end
script.Parent.Touched:connect(Touch) --Listens out for Touchers.
0
Is this a LocalScript? MarkedTomato 810 — 3y
0
It Index's as a nil because there is no 'leaderstats' within plr. If there is a leaderboard you'll need to specify it as "leaderstats" and if it is already it needs to be within the StarterPlayerScripts. You can also rewrite and create an Instance where you can create a leaderboard within the script. InfamousScript 2 — 3y
0
i already have an leaderstats, and it's in a Script not localscript Komas19 34 — 3y
0
If you already have a leaderboard system in-game change the leaderstats variable to local leaderstats = game:FindFirstChild("Leaderboard") -- Leaderboard being whatever the leaderboard name is InfamousScript 2 — 3y

1 answer

Log in to vote
-1
Answered by 3 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

Changed :

local Players = game:GetService("Players")
local Teleport = "Part2"

script.Parent.Touched:Connect(function(hit)
    local player = Players:GetPlayerFromCharacter(hit.Parent)
    local leaderstats = player.leaderstats
    if leaderstats.Prestige.Value >= 1 then
        if script.Parent.Locked == false and script.Parent.Parent:findFirstChild(Teleport).Locked == false then
            script.Parent.Locked = true script.Parent.Parent:findFirstChild(Teleport).Locked = true
          local Pos = script.Parent.Parent:findFirstChild(Teleport)
            hit.Parent:moveTo(Pos.Position) wait(1) script.Parent.Locked = false script.Parent.Parent:findFirstChild(Teleport).Locked = false
        end
    end
end)
0
thx it works now Komas19 34 — 3y
0
You have some deprecation in your code, for example: moveto should be MoveTo, :findFirstChild should be:FindFirstChild JesseSong 3916 — 3y
0
You didn't explain what you changed, on the code so that should have been in the comments. JesseSong 3916 — 3y
0
i only help him fix : Workspace.Zones.Portal1.TeleportPads.Part1.Script:7: attempt to index nil with 'leaderstats , and he can see local player then he can remember this kimdinh108 13 — 3y
Ad

Answer this question