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

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

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!

1 comment

0

Please use the Lua formatting for your code. I don't understand this.

1 answer

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.

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