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

How to make a part that kills you if your sitting?

Asked by
k6jn 5
4 years ago

Tried another persons script local model = script.Parent local Player = game.Players.LocalPlayer.Character --Get the player's character here function onTouch(part) if Player.Humanoid.Sit == true then if part.Parent:FindFirstChild("Humanoid") ~= nil then part.Parent.Humanoid.Health = 0 end end

function ConnectParts(obj) if obj then if obj:IsA("Part") then obj.Touched:connect(onTouch()) else if #obj:GetChildren() > 0 then for i, v in pairs(obj:GetChildren()) do ConnectParts(v) end end end end end

ConnectParts(model) end

pelase help, Thanks!

0
Please use the Lua formatting for your code. I don't understand this. rabbi99 714 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

I think the problem is that you either used LocalPlayer inside a ServerScript or that you used a LocalScript inside a part, which would not run. Put the following code inside a ServerScript which is inside your part.

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChildOfClass("Humanoid") then
        local humanoid = hit.Parent:WaitForChild("Humanoid")

        if humanoid.Sit == true then
            hit.Parent:BreakJoints()
        end
    end
end)

Also, it looked like you had a variable that said model = script.Parent. This would not work if script.Parent was a model, as a model does not have a Touched event, and please use formatting next time you ask a question.

Ad

Answer this question