Alright so basically, i got a script in which it has a table full of words, everytime a player joins it picks a certain word, and the word is a value of an ObjectValue, and the script checks if the value is (for example) “Fast” then the player’s speed is set to 20.
game.Players.PlayerAdded:Connect(function(player)
local Events = {
"Deadly Disease",
"Giant",
"Small",
"Very Old",
"Young",
"Fast",
"Slow",
"High jump",
"Small jump"
}
local EventsValue = game:GetService("ServerStorage").Events_value
EventsValue.Value = Events[math.random(0, #Events)]
print(EventsValue.Value)
if EventsValue.Value == "Fast" then
player.Character:FindFirstChild("Humanoid").WalkSpeed = 20
elseif EventsValue.Value == "Very Old" then
player.Character:FindFirstChild("Humanoid").WalkSpeed = 6
end
end)
everything works but when the word 'Fast" is selected i get
ServerScriptService.Script:19: attempt to index nil with ‘FindFirstChild’
It’s because the humanoid hasn’t loaded yet, even though the player is registered in the game the humanoid might still be loading you can fix this with wait for child or adding a delay.
The error is indicating that you’re calling nil:FindFirstChild(), which means that the player’s Character doesn’t exist when the script is trying to reference it.
To resolve this, you can create a variable for the Character that references it if it exists, or waits for it to load:
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local Character = player.Character or player.CharacterAdded:Wait()
-- Continue
end)
The random number it chose might’ve been 0, which could have caused that error because the Events table wouldn’t have anything stored at that index (because indexes for arrays start at 1). Updating that to the following should resolve that error: