Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

3 comments

0

I had tried player:WaitForChild("Character") and it didn't work. This did. Thank you.

2

@TheDoubleJ0Jake0Jam  Character isn't a child of player - it's a property.

0

@Perci1 That is good to know. Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.