Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can i make this kill all players on start?

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.

6 comments

1

u got two periods my dude

0

I don't think you can concatenate it with ".." since it's an object

0

Omg INOOBE

0

Gonna up your comment :) am a big fan

0

I see that you typed print(player) without those: ""

0

KOMKO190 what no thats a variable

1 answer

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

5 comments

0

Actually, repeat loops don't have ends, their "end" is "until" and you need a wait() 

0

Haha! -- to wont judge

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

0

i messed a bit with it and made it work thanks

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

This discussion is preserved as it was. New answers, comments, and votes are closed.