So I have a random number generator which searches through a number of players which generates their name. For some reason, it keeps giving me the Humanoid is not a valid member of model, even though the player is there. I am not sure why it is doing that. I even tried waitforchild.
My code:
repeat
local randomhammer = random:NextInteger(1, #hammertable)
person = hammertable[randomhammer]
timoutw = timoutw + 1
wait()
until game.Players:FindFirstChild(person) or timoutw > 60
if not game.Players:FindFirstChild(person) then
getranplayer()
person = ranp1
end
local plare = game.Players:FindFirstChild(person)
local timout2 = 0
repeat wait() timout2 = timout2 + 1 until plare.Character or timout2 > 100
kidnapperson = person
if plare.Character then
local humanoid = plare.Character:FindFirstChild("Humanoid")
if humanoid then
game.Workspace.Chair.Seat:Sit(plare.Character.Humanoid)
plare.Character.Humanoid.Health = 0
end
end
Get random player generates a random player and works fine. Any healp is appreciated.
Try using a print on “plare” to see what it returns to you, if it returns the actual player. Try printing the character to see if it even prints, if it prints the character’s name, then its working, if not, theirs a problem in one of them.
Edit: Try indenting your code so it can be easier to read for us to help you.
game.ReplicatedStorage.Hammers.Event:Connect(function(plrtable)
hammerevent = true
hammertable = plrtable
for i,v in pairs(hammertable) do
print(v)
end
end)
local amount = 3
local players = {}
function hi(x)
if amount > 0 then
amount = amount - 1
local y = x.Backpack
local z = game.Lighting["Hammer"]
z:Clone().Parent = y
table.insert(players, x.Name)
if amount == 0 then
game.ReplicatedStorage.Hammers:Fire(players)
end
local char = x.Character
end
end
script.Parent.ClickDetector.MouseClick:Connect(hi)