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

Remove annoying errors?

Asked by 8 years ago

I am trying to make a kill brick script as simple as possible for a game I am making. It works of course as its basic and should work. The only issue is that it does has some slight console errors. Errors: Ill start by saying that its designed so that if anything touches the brick to break its joints. My issue is for some odd reason I have 2 guns in the player starter pack and what happens it the part thinks they are touching it but they are not. (I am on a part that is suspended over the baseplate(The base plate is the kill brick)) Anyway for some reason the brick things the gun is touching it but its not and then tried to break its joints only to keep posting the error in my console that the tool does not have any joints to break.

Heres my code:


script.Parent.Touched:connect(function(hit) hit.Parent:BreakJoints() end)

I understand this is probably as short as its gonna get but if it can be shrunken any other way please post it. Also I wasn't sure how but essentially I only want it to break the player that touched it's joints, not any other item or part.

0
It's not a good idea to make it small but less efficient &  successful aquathorn321 858 — 8y

3 answers

Log in to vote
1
Answered by 8 years ago

Alright brother. Here's a working script I just wrote and tested. Nice, simple, and it works:

-- Just put this script into the Part and bam. 
function onTouched(hit)
    local human = hit.Parent:FindFirstChild("Humanoid")
    if (human ~= nil) then
        human.Health = 0
    end
end

script.Parent.Touched:connect(onTouched)
Ad
Log in to vote
0
Answered by 8 years ago

The smallest way to do it might be

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") ~= nil then
        hit.Parent.Humanoid.Health = 0
    end
end
Log in to vote
0
Answered by 8 years ago
script.Parent.Touched:connect(function(hit)
if hit.Parent:IsA("Tool") then
else
    hit.Parent:BreakJoints()
end)

All the other scripts/answers work ^ But this is more specific to your dilemma.

Answer this question