Hello Robloxians !!
I have a problem with the Sit()
function of a Seat
.
I get this error: Sit : param is not a Humanoid or humanoid is dead
.
Code
Players.CharacterAutoLoads
is disabled .
Server-Side Script
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
local Humanoid = Character:WaitForChild("Humanoid")
-- local Seat = ...
Seat:Sit(Humanoid)
end)
Player:LoadCharacter()
end)
Please help me
1 Like
sit the humanoid not the character
1 Like
Sorry I made a mistake in writing the code but I put the Humanoid.
check if the humanoid is nil, if it is, then reload the character and try sitting them again
1 Like
It doesn’t change anything. I added:
if not Humanoid then
Player:LoadCharacter()
end
does the player exist when you try sitting them
1 Like
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
Seat:Sit(Humanoid)
end)
Player.CharacterAutoLoads = true
end)
LoadCharacter will kill the humanoid, causing the error.
2 Likes
they said characterautoloads is off, which is why they used loadcharacter
1 Like
Then set it to true:
Player.CharacterAutoLoads = true
1 Like
i think instead of loading the character by code, just let them load in automatically, then disable characterautoloads
1 Like
I don’t want to do that, that’s precisely why I load it via the script.
Well your problem is the humanoid is dying because it’s getting respawned, which is causing the error. Something like this might work:
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
wait(5)
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
Seat:Sit(Humanoid)
end)
Player:LoadCharacter()
end)
1 Like
Don’t want to add a wait(5)
because the player waits for 5 seconds while the game is ready.
Then you’re out of luck. Add a loading screen.
As I said multiple times , your error is happening because the humanoid is dead, due to you resetting the character .
You can quickly set CharacterAutoLoads to true, and set it to false after, but that’s about all you can do.
2 Likes
I do not reset the character because Players.CharacterAutoLoads
is false and the user has just joined the game.
CommanderRanking:
Then you’re out of luck. Add a loading screen.
As I said multiple times , your error is happening because the humanoid is dead, due to you resetting the character .
You can quickly set CharacterAutoLoads to true, and set it to false after, but that’s about all you can do.
I just tested with Players.CharacterAutoLoads = true
and I still have the same error .
Did you remove the Player:LoadCharacter()
?
1 Like
I deleted that, and now nothing works anymore.
heisIlan
(Ilan)
May 11, 2022, 4:17pm
#19
Orrrrrrrrrrrrrrrr,
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
repeat task.wait() until Character:FindFirstChildOfClass("Humanoid")
local Humanoid = Character.Humanoid -- removed the findfirstchild because we know the humanoid exist and findfirstchild very slightly makes the script slower
Seat:Sit(Humanoid)
end)
Player:LoadCharacter()
end)
1 Like
Thank you so much @heisIlan for your second solution.
1 Like