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

What is the script that kill you when you touch the part?

Asked by 4 years ago
Edited 4 years ago

1) function onTouched(part) local h = part.Parent:findFirstChild("Humanoid") if h~=nil then h.Health = 0 end end script.Parent.Touched:connect(onTouched)

2) function onTouched(part) local h = part.Parent:findFirstChild("Humanoid") end end script.Parent.Touched:connect(onTouched)

3) function onTouched(part) local h = part.Parent:findFirstChild("Humanoid") if h~=nil then h.Health = 0 end

0
Please use code blocks when you're typing a script. User#32819 0 — 4y

3 answers

Log in to vote
1
Answered by 4 years ago

This one is more simple, since i assume you are a beginner!

local Part = script.Parent -- Here we are creating a variable, so we can acess the part easier than needing to type script.Parent everytime we need to adjust the part

Part.Touched:Connect(function(hit) -- So here is a new thing for you. Events basically fire something when you do something!
    if hit.Parent:FindFirstChild("Humanoid") then -- Hit is the part that you touch the brick with. And if it contains a humanoid we want to fire something.
        hit.Parent.Humanoid.Health = 0 -- We are saying the health of the humanoid equals to 0. Remember to have to equal signs if it is in a if statement.
    end
end) -- Self-Explanatory.

Good luck on your scripting progress

1
I was just about to type that script in lol, i was 7 minutes too late AcrylixDev 119 — 4y
0
Yep. Nice job explaining it. FrostedFlakes67 71 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

This is the working one, the first one

function onTouched(part)  -- a function for when a part is touched
 local h = part.Parent:findFirstChild("Humanoid") -- find a humanoid inside the toucher
if h~=nil then -- if the humanoid is not nil then
 h.Health = 0 -- make the humanoids health 0
end 
end 
script.Parent.Touched:connect(onTouched) -- connecting it to the function
Log in to vote
0
Answered by
Geobloxia 251 Moderation Voter
4 years ago

This is one way to do it.

script.Parent.Touched:Connect(function(hit)
    -- if the script.Parent is touched, the function activates
    if game.Players:GetPlayerFromCharacter(hit.Parent) then
        -- this makes so it has to be a player, no NPCs
        local hum = hit.Parent:FindFirstChild("Humanoid")
        if hum then
            -- checks to see if it has a humanoid
            hit.Parent:BreakJoints()
            -- breaks the joints in the character, killing it
        end
    end
end

Answer this question