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

I cannot get this kill brick script to work :/ Can someone tell meh what I ain't doing right?

-- I just set random variables(These are variables right guys?) for the purpose of the script.
local Scripter = "Over 9000"
local Memes = 750
local Killer = true

local KillBrick = script.Parent  --KillBrick is the part that this code is inside lol

if Killer == true then
	function PlayerTouched()
		game.Players:GetPlayers()
		Parent.Humanoid.Health = 0
		end
	end



Why won't this work??? ugh xD

2 answers

 -- These are variables
local Scripter = "Over 9000" -- String variable
local Memes = 750 -- Number variable
local Killer = true -- Boolean variable

local KillBrick = script.Parent -- Parent of the script

if Killer == true then -- Not necessary but you can use it for whatever purpose
	KillBrick.Touched:Connect(function(hit) -- Touched event fires when someone/something touches the brick
		if hit.Parent:FindFirstChild("Humanoid") then -- makes sure the "something" is a player/character
			local character = hit.Parent -- get character
			local humanoid = hit.Parent:FindFirstChild("Humanoid") -- get humanoid
			humanoid.Health = 0 -- kill character
		end
	end)
end

GetPlayers() Wasn't needed in this case, as with the touched event you can easily get the player/character.

3 comments

1

Look's promising.

1

Thanks

0

Use GetPlayerFromCharacter

-- I just set random variables(These are variables right guys?) for the purpose of the script.
local Scripter = "Over 9000"
local Memes = 750
local Killer = true

local KillBrick = script.Parent  --KillBrick is the part that this code is inside lol

KillBrick.Touched:Connect(function(hit)
	h = hit.Parent:FindFirstChild("Humanoid")
		if h then
			h.Health = 0
end

You have to set a .Touched event with the brick you want the player to touch. Just because you wrote PlayerTouched as a function doesnt mean it will work like that. Function names dont matter. What does matter is how you call them.

If it doesnt work, then it's either because I put only one end or I forgot the right Health property. I didnt do this in studio i just made it up

2 comments

0

Health is right, just you forgot the end like you said, good job though

0

Fail

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