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

How to fix attempt to index nill parent?

Asked by 4 years ago

Ok so I am getting an error when I type in the console it tells me this!

Error:

114:04:22.163 - script.Parent.Crouch.MouseButton1Click:Connect(function()
214:04:22.164 -  crouch()
314:04:22.165 - end):1: attempt to index nil with 'Parent'

Code:

01script.Parent.Crouch.MouseButton1Click:Connect(function()
02    crouch()
03end)
04 
05Full code:
06 
07local player = game.Players.LocalPlayer
08 
09local userInputService = game:GetService("UserInputService")
10 
11local animationID = "rbxassetid://04979694208"
12 
13local animPlaying = false
14 
15function crouch()
View all 61 lines...

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

It's because crouch() is an unknown function. Scripts run from line 1 to line x. So to fix this issue. Simply have function crouch() at the top of your script

01function crouch()
02    if player:FindFirstChild("Contestant") then
03            if animPlaying == false then
04                local animObj = Instance.new("Animation")
05                animObj.AnimationId = animationID
06                local loadedAnim = player.Character.Humanoid:LoadAnimation(animObj)
07                loadedAnim:Play()
08                player.Character.Humanoid.WalkSpeed = 10
09                animPlaying = true
10                script.Parent.Crouch.ImageColor3 = Color3.fromRGB(26, 144, 255)
11                script.Parent.Crouch.TextLabel.BackgroundColor3 = Color3.fromRGB(26, 144, 255)
12                print("Playing")
13            else
14                print("Stopping")
15                for i , v in pairs(player.Character.Humanoid:GetPlayingAnimationTracks()) do
View all 62 lines...
0
What I mean is crouch is nil because there isn't an existing function yet. Just put the function script above line 1 Skydoeskey 108 — 4y
0
so u mean put the whole script? for function crouch() AviaFlyHigh 15 — 4y
0
Watch the edit of my awsner Skydoeskey 108 — 4y
Ad

Answer this question