Why won't .Changed for a string value work?
I want to make a local script run a function when the value of a string value called "EquippedWeapon" is changed. Here I have a local script which changes the string value upon a TextButton being pressed
01 | local EquippedWeapon = game.Players.LocalPlayer:WaitForChild( "EquippedWeapon" ).Value |
09 | Buttons [ 1 ] .MouseButton 1 Click:Connect( function () |
10 | EquippedWeapon = "Katana" |
12 | print ( "EquippedWeapon" ) |
Now, here's a local script in StarterPlayerScripts which runs a function when EquippedWeapon's value changes.
1 | local Player = game.Players.LocalPlayer |
2 | local EquippedWeapon = Player:WaitForChild( "EquippedWeapon" ).Value |
4 | EquippedWeapon.Changed:Connect( function () |
5 | print ( "Equipped Weapon value has been changed." ) |
What should happen is that when EquippedWeapon's value is changed to "Katana", it should print a message. But the error message is this:
"Players.trapiz.PlayerScripts.GearChecker:4: attempt to index field 'Changed' (a nil value)"
Thanks :)