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

How do I make a script that prevents/auto-removes joints from parts attached to the character?

Asked by 9 years ago

Situation: someone attaches parts to their character. I don't want this happening.

The parts' sides are welded, and some are universal.

My solution: Made a script that waits for JointsService.ChildAdded, checks if it's connected to a body part (if child.Part0 or child.Part1 is either named a body part or parented to a hat), then destroys it.

local bpt = {}
bpt["Left Arm"] = true
bpt["Left Leg"] = true
bpt["Right Arm"] = true
bpt["Right Leg"] = true
bpt["Head"] = true
bpt["Torso"] = true
bpt["Hat"] = true --in case the part is a hat mesh thing, then its parent is a hat

game.JointsService.ChildAdded:connect(function(child)
    print("A joint has been created.") --Flag 1
    if bpt[child.Part0.Name] or bpt[child.Part1.Name] or bpt[child.Part0.Parent.Name] or bpt[child.Part1.Parent.Name] then
        print("And it's an illegal joint. How fun. Goodbye.") --Flag 2
        child:Destroy()
        print("*insert function here informing the player that what he/she just did is not allowed*") -- Flag 3
    end
end)

For some reason, it doesn't work. I don't see any errors in the output. All three print functions are outputted, which I assume means that the entire code was executed smoothly.

Why doesn't it work? ._.

0
Why not use :GetConnectedParts() instead? Since not all joints are in the JointsService. MrNicNac 855 — 9y
0
I did not know about that... wow. Thanks dude. ;D MarcelinesRevenge 0 — 9y

Answer this question