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

"Attempt to index nil with Stats"=?

Asked by
Qariter 110
4 years ago

I was attempting to make a button that gives someone a certain value, but it seems to break on lines 20,21,24. Could anyone help?

Error: Attempt to index nil with 'Stats'

local pressed = false

script.Parent.Touched:Connect(function(part)
    if part.Parent:FindFirstChild("Humanoid") then
        print("found hmanoid")
        if not part.Parent:FindFirstChild("GotReward") then
                print("hasn't got reward")
            if game.Players:GetPlayerFromCharacter(part.Parent) and pressed == false then
                    print("pressed.")
                pressed = true
                local player = game.Players:GetPlayerFromCharacter(script.Parent)
                local gotreward = Instance.new("BoolValue")
                gotreward.Name = "GotReward"
                gotreward.Parent = part.Parent
                script.Parent.press:Play()
                script.Parent.Transparency = 1
                script.Parent.SpringConstraint.Visible = false
                        script.Parent.Parent.Pressed.Transparency = 0
                script.Parent.Parent.Pressed.SpringConstraint.Visible = true
                print(player.Stats:FindFirstChild("OwnsSummerNoob").Value)
                if player.Stats:FindFirstChild("OwnsSummerNoob").Value == 0 then
                                        print("giving.")

                    player.Stats:FindFirstChild("OwnsSummerNoob").Value = player.Stats:FindFirstChild("OwnsSummerNoob").Value + 1
                    game.ReplicatedStorage.SendRewardMessage:FireClient(player,"You've unlocked: Summer Noob")
                else
                                        print("alreadyhave")
                    game.ReplicatedStorage.SendWarn:FireClient(player,"You already have Summer Noob, so you'll get 500 points instead.")
                    player.Stats.Points.Value = player.Stats.Points.Value + 500
                end
                game.Workspace.SummerEventButtonPressed.Value = true
                wait(5)
                                script.Parent.Transparency = 0
                script.Parent.SpringConstraint.Visible = true
                        script.Parent.Parent.Pressed.Transparency = 1
                script.Parent.Parent.Pressed.SpringConstraint.Visible = false
                pressed = false
            end
        end
    end
end)
1
On line 11 the player is found from "script.Parent" maybe that's your error. Player1_Joined 271 — 4y
0
Oof! i see now.. Thank you! I wish i could give you a upvote. Qariter 110 — 4y

Answer this question