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

"Workspace.Blox.BloxScript:30: attempt to index a nil value." Error issues?

Asked by 6 years ago
01Blox.Touched:Connect(function(touch)
02    if CanTouch.Value == true then
03        CanTouch.Value = false
04        Torso = touch.Parent:FindFirstChild("Torso")
05        if Torso ~= nil then
06            local Player = Torso.Parent
07            Blox.CanCollide = false
08            local PlayerName = Player.Name
09            local BloxStat = game.Players:FindFirstChild(PlayerName):FindFirstChild("leaderstats"):FindFirstChild("BloxCounter")
10                BloxStat.Value = BloxStat.Value + 1
11                Ghostify()
12        end
13    end
14end)

The above code is for the collectibles in my game which I call "Blox." But for some reason, I keep getting the error: Workspace.Blox.BloxScript:30: attempt to index a nil value. I believe its coming from the end of the line which says "FindFIrstChild("BloxCounter")" but a value is named that from the start of the game so it shouldn't be nil. I really don't know what else could be going on.

0
There is no line 30... User#19524 175 — 6y
0
Post full script please. RAYAN1565 691 — 6y
0
Sorry, I didn’t realize it renumbered the lines. I’ll put the full script in an answer. tygerupercut3 68 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago
01local Blox = script.Parent
02local Pos = Blox.Position
03local BodyPosition = Blox.BodyPosition
04local BodyPositionStopped = game.Workspace.BodyPosition
05local PlayerValue = Blox.PlayerValue
06--Players = game:GetService("Players")
07local CanTouch = Blox.CanTouch
08 
09function Ghostify()
10    local i = 0
11    repeat
12        BodyPosition.MaxForce = BodyPositionStopped.MaxForce
13        BodyPosition.Position = Torso.Position
14        Blox.Transparency = Blox.Transparency + 0.05
15        wait(0.05)
View all 36 lines...

Line 30 is the one that sets BloxStat to BloxCounter. Also the ghostly function is there to add a smooth collecting animation so it looks like the collectible floats into your player instead of disappearing instantly.

Ad
Log in to vote
0
Answered by
exvient 30
6 years ago

Use a remote event instead, and have another script handle the remote event function to award it to the player in leaderstats. That way no exploiters can manipulate it and you can edit and potentially fix the script in the future.

Answer this question