I’m trying to break joints on a model when the primary part of that model, touches a part. So far I’m not getting anywhere. I’m also trying to use math.random to randomize whether the breakjoints occurs on the model or not.
local model = math.random(1,2)
local hit = workspace.ColliderPart
while true do
wait(1)
if model == 1 then
print ("Going Down")
end
function hit()
if script.Parent.PrimaryPart.Touched:Connect(hit) then
script.Parent:BreakJoints()
end
if model == 2 then
print ("Not Going Down")
end
end
end
Hi @2MuchRaining, hopefully, this simple script can help you in the right direction to create your experience.
local model = script.Parent
local colliderPart = game.Workspace.ColliderPart
model.PrimaryPart.Touched:Connect(function(hitPart)
if hitPart == colliderPart then
if math.random(1,2) == 1 then -- 50% chance, similar to what you posted
model:BreakJoints()
script:Destroy() -- might as well remove the script if this is its only purpose, you cannot break the model twice, can you?
end
end
end)
Are there any errors in the console?
Besides that, when looking at your code it seems the hit variable at line 2 supersedes the first while true do loop. Which by the way isn’t a good way of going about a probability.
there’s no errors in the console. It just doesn’t break the welds of the model when the models primary part touches the collider part. I’ve tried XandertjeKnals script.
If you’re using Xander’s script, you can try moving the function’s connection to the end of the code.
Another bit I’d like to point out is that you can probably put the math.random on the same line as the “hitPart == colliderPart” to eliminate one of those ends.