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

Script working fine last week. It is broken now, but why?

Asked by
AZDev 590 Moderation Voter
8 years ago
local player = game.Players.LocalPlayer

script.Parent["GunScript V5"].Disabled = true

script.Parent.Equipped:connect(function()
    script.Parent["GunScript V5"].Disabled = false
end)

script.Parent.Unequipped:connect(function()
    script.Parent["GunScript V5"].Disabled = true
end)

player.Character.Humanoid.Died:connect(function() -- errors here
    script.Parent["GunScript V5"].Disabled = true
end)

--This script prevents the gun from being fired when it is not equipped or if the player died.

error is: "Attempt to index field 'Character' (a nil value)"

1 answer

Log in to vote
0
Answered by 8 years ago

The player's character may not be loaded when this script runs. To ensure the character exists, place this after line 2 in your script:

repeat wait() until player.Character
0
I had tried player:WaitForChild("Character") and it didn't work. This did. Thank you. AZDev 590 — 8y
2
@TheDoubleJ0Jake0Jam  Character isn't a child of player - it's a property. Perci1 4988 — 8y
0
@Perci1 That is good to know. Thanks! AZDev 590 — 8y
Ad

Answer this question