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

attempt to index field 'Character' (a nil value)?? Combat script

So im very new to scripting and for practice im working on a my hero academia game and atm im trying to make a basic combat script and even so im just trying to make it play the animations then add on to it i keep getting an error

07:25:41.181 - Players.viaticeal664.Backpack.Melee.LocalScript:3: attempt to index field 'Character' (a nil value)

Here is the script atm https://pastebin.com/nSN8K4Eg ill take any type of criticism you have because im trying to get better

1 comment

0

Sorry for bad grammer im tired asf

1 answer

✓ Accepted answer

That's happening beacuse you're using a local script, thus you need to wait in order for the player's character to load, to do that

local character = game.Players.LocalPlayer.CharacterAdded:Wait() 

CharacterAdded is just an event that checks if a character was added, and :Wait() which you might've never seen is basically the same as :Connect(), but it's only available for certain events, mainly events that have to do with waiting for something to happen such as this character event. :Wait() will stop the script for a second (in other words yield the script) until the character is loaded, and once it's loaded it will return the character and the script will continute working

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