local RemainingTracks = ReplicatedStorage.Remotes.GetGlowstickHealth:InvokeServer(script.Parent.Name)
local Songs = 0
local EquippedArray = {}
script.Parent.Equipped:Connect(function() -- LINE 18 IS HERE
EquippedArray[tostring(Songs)] = true
end)
ReplicatedStorage.Remotes.TrackOver.OnClientEvent:Connect(function()
if EquippedArray[tostring(Songs)] == true then
RemainingTracks -= 1
ReplicatedStorage.Remotes.AdjustGlowstickHealth:FireServer(script.Parent.Name)
end
Songs += 1
end)
if RemainingTracks == nil or RemainingTracks == 0 then
ReplicatedStorage.Remotes.ConsumableBroken:FireServer(script.Parent.Name)
script.Parent:Destroy()
script:Destroy()
end
How can script.Parent be nil with the code still executing??
Any help would be appreciated
So, according to what line 18 is, this is not the error. Though, what are you trying to do with RemainingTracks -= 1? RemainingTracks is a variable of invoking the server, not a variable for a value. So, what are you trying to do here?
InvokeServer returns a value, meaning that the variable becomes that value.
It’s important to note that for 7 out of 8 testing players, this script works 100% as intended. Just every now and then this error appears and the person’s glowstick doesn’t work.
I don’t understand what you mean by this. Clearly the output states what the error is, it’s on line 18 that it’s indexing nil with equipped.
I would try putting the equip connection to the end of the script or adding some wait before it. Cause I think the error is just that the tool isn’t fully loaded and that’s why it says that script.Parent.Equipped doesn’t exist. But I am not sure…
The error attempt to index nil occurs when the parent of who’s property we are trying to index is nil. Here we try to index Equipped property from a nil value that is script.Parent.
Sorry for this kind of off-topic post, but:
It’s now that I’m realizing that you thought I meant the error that shows in the output is not the error. I meant the error that I was stating (which apparently isn’t an error), wasn’t the error shown in the output.
This is great, but unfortunately it doesn’t fix this error because I’m not destroying the tool at any point other than when the life is 0 and when the life is set to 0 it’s destroyed in the function below. However, the script never runs that condition at the bottom because it errors on line 18 as soon as it runs.
I made a couple of changes on the server and it has reduced the number of times this is happening to about 1 in 16 but the fact that is does still happen sometimes is baffling.
I literally can’t figure out why this is happening