I tried making a script that should kill all players on start but it does not work. Here's the code (note that i am a beginner scripter) :
local Players = game:GetService("Players") game.Players.PlayerAdded:connect(function(player) print(player) local pname = player.Name wait(4) local homanuid = game.workspace..player.Name local hooman = homanuid:FindFirstChild("Humanoid") repeat until hooman.Health == 0 hooman.Health = -10 wait(0.2) end)
What's wrong? And the error is "attempt to concatenate field 'workspace' (a userdata value)" on line 7.
First of all, you only need one .
to access the children of an object. Also, you can use the keyword workspace
rather than game.Workspace
(note the capital W when using game.
in front!). Finally, you can get the character by doing player.Character
instead.
I'm not sure what's with your variable names but I won't judge:
local Players = game:GetService("Players") -- capital C for Connect! lowercase version is deprecated game.Players.PlayerAdded:Connect(function(player) print(player) wait(4) local homanuid = player.Character -- better way to access character local hooman = homanuid:FindFirstChild("Humanoid") repeat hooman.Health = -10 wait(0.2) until hooman.Health == 0 end)
Hope this helps! :)