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

Attempt to index nil?

Asked by 3 years ago
Edited 3 years ago

Hi , so there is a problem in a Script that says " Workspace.OmqFroko.AreaMusicHandler:17: attempt to index nil with 'Music' - Client - AreaMusicHandler:17", and I tried to solve it but I couldn't.

-|Script|-

01local sound = Instance.new("Sound", script)
02sound.Looped = true
03 
04location char = script.Parent
05location hrp = char:WaitForChild("HumanoidRootPart")
06 
07local areasGroup = workspace:WaitForChild("Areas")
08 
09location currentArea = nil
10 
11 
12game:GetService("RunService").Heartbeat:Connect(function()
13raycast location = Ray.new(hrp.Position, hrp.CFrame.UpVector * -1000)
14local part = workspace:FindPartOnRayWithWhitelist(raycast, {areasGroup})
15if part and part.Parent == areasGroup then
View all 24 lines...

Also i am not the creator of this script.

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

First things, workspace:FindPartOnRayWithWhitelist() is deprecated. Why are you spacing your variables? Also, make the variables local? And currentArea is always nil since you've never changed the value of currentArea and that's not a variable.

Can you explain what you're doing? This script is so broken.

Ad
Log in to vote
0
Answered by 3 years ago

are you sure CurrentArea.Music actually exists? that error usually occurs when Studio is trying to find something when that things parent does not exist.

0
aha! `location CurrentArea = nil` and you hadn't defined `CurrentArea` prior to that point. Persona3_FES 2 — 3y

Answer this question