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

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

Asked by 5 years ago
Edited by M39a9am3R 5 years ago
-- 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

Log in to vote
2
Answered by 5 years ago
 -- 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.

1
Look's promising. AswormeDorijan111 531 — 5y
1
Thanks MythicalShade 420 — 5y
0
Use GetPlayerFromCharacter FrezeTagger 75 — 5y
Ad
Log in to vote
1
Answered by 5 years ago
Edited by M39a9am3R 5 years ago
-- 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

0
Health is right, just you forgot the end like you said, good job though MythicalShade 420 — 5y
0
Fail AswormeDorijan111 531 — 5y

Answer this question