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

It says "Workspace.WinPart.WinScript:17: attempt to index nil with 'leaderstats", help? [Solved]

Asked by 3 years ago
Edited by Ziffixture 3 years ago

This used to work previously. Then I tried adding a debounce on, and it didnt work. Instead of researching what was going on, I decided to use values to debounce, a terrible idea. I messed up the script, tried to revert it, and I got an error. Can somebody please help me? This error is probably obvious and i just didn't catch it.

EDIT: I think I know what I did wrong, I just want confirmation. But if I dont get it in a while I'll just try it out and see if it works

EDIT2: I FIGURED IT OUT MYSELF

local WinPart = script.Parent

WinPart.Touched:Connect(function(hit)   
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")

    if player then


            local leaderstats = player:FindFirstChild("leaderstats")

            if leaderstats then

                    local player = game.Players.LocalPlayer
                    local Location = game.Workspace.TeleportLocation

                    player.leaderstats.Wins.Value = player.leaderstats.Wins.Value + 1
                    hit.Parent.HumanoidRootPart.CFrame = CFrame.new(Location.Position)

                    wait(1)
            end
        end
end)
0
Also, I remember the code being longer, maybe that was just be adding the debounce in MrGustavio 34 — 3y
0
By context, I assume this code is written in a regular Script, therefore, line 14 is likely where you're experiencing your issue. Ziffixture 6913 — 3y
0
The LocalPlayer pointer refers to a Client—thus why LocalScripts are the only Instance able to reference it—since this program is operating on the Server, the return value is null. Ziffixture 6913 — 3y
0
Regardless, you've already allocated the proper Player Object on line 4, simply remove 14 and you're good to go! Ziffixture 6913 — 3y
0
Well, its fixed anyway. I thought I was calling the thing at the beggining of the script. All I had to do was change the capitalization and it fixed itself. MrGustavio 34 — 3y

Answer this question