Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can i make this kill all players on start?

Asked by 6 years ago

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.

1
u got two periods my dude INOOBE_YT 387 — 6y
0
I don't think you can concatenate it with ".." since it's an object ABK2017 406 — 6y
0
Omg INOOBE mixgingengerina10 223 — 6y
0
Gonna up your comment :) am a big fan mixgingengerina10 223 — 6y
View all comments (2 more)
0
I see that you typed print(player) without those: "" KOMKO190 0 — 6y
0
KOMKO190 what no thats a variable Megablocker70 0 — 6y

1 answer

Log in to vote
0
Answered by
chomboghai 2044 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

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! :)

0
Actually, repeat loops don't have ends, their "end" is "until" and you need a wait()  User#19524 175 — 6y
0
Haha! -- to wont judge ABK2017 406 — 6y
0
This won't work because A.) it'll crash the client because there is no wait() and B.) the loop stops the script completely even with the wait() because the part that kills the player is after the loop poke7667 142 — 6y
0
i messed a bit with it and made it work thanks Megablocker70 0 — 6y
0
Oh right. For some reason I referenced his way of using the repeat until loop and I completely forgot how it worked :p fixed it tho chomboghai 2044 — 6y
Ad

Answer this question