For some reason in the following script it always errors at local Character = game.Players.ThePlayer.Character
The error says that “ThePlayer is not a valid member of Players “Players””
I even had it print the ThePlayer right before and it printed my name.
It Should work since I am manually going through the serverside and setting the the value called player my name, which is a valid member of the Players.
value = script.Parent.Parent.Player
value.Changed:Connect(function(NewValue)
wait(.5)
print(NewValue)
local ThePlayer = NewValue
local Character = game.Players.ThePlayer.Character --ERROR HAPPENS HERE
local Humanoid = Character:WaitForChild("Humanoid")
I even tried making it this
value = script.Parent.Parent.Player
value.Changed:Connect(function(ThePlayer)
wait(.5)
print(ThePlayer)
local Character = game.Players.ThePlayer.Character --ERROR HAPPENS HERE
local Humanoid = Character:WaitForChild("Humanoid")
Still did not work
I am 100% sure the value I am entering into the StringValue is correct as I copy and pasted my NAME from the players and it even printed my username in both scripts.
So can anyone help me with this problem? It is probably something basic I am missing.
Thank you!
Value = script.Parent.Parent:WaitForChild("Player")
local Players = game:GetService("Players")
Value.Changed:Connect(function(PlayerName)
local Player = Players:FindFirstChild(PlayerName)
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
end)
This issue occurred because you were trying to find a member named “Character” inside of a string value of the player’s name as opposed to the player instance itself, I’ve made some changes to make everything obvious.
I know this topic is solved but I just wanted to quickly mention that you should always check if the character exists before attempting to get the Humanoid, because in the event that the player’s character died and was in the process of getting a new character on respawn, or if the player left the server, the character variable would be nil, and you can’t WaitForChild on a nil variable, so it would throw an error in the output. Seeing that it’s in a connection means that the script wont necessarily break, but if it wasn’t then it would break the script.