Hey, developers!
For my huge 100K update to my currently mediocre shark survival game, Megalodon Survival, I’m adding gamemodes. There are a few of them, but issues start with the two gamemodes I have that include multiple sharks. Say a “Double” gamemode, for example. My shark models were originally taken from the Toolbox but have gone through large edits, so allow me to continue to refer to them as mine. The sharks have a break script in them which breaks all joints of whatever a certain part touches. This system works, unless there is another shark. If the part of the shark touches another shark, its mesh will detach from the rest of it, leaving you with some sort of ghost shark.
(Original Break Code. Credit to @TestDS.)
local dangervelocity = 10
script.Parent.Touched:Connect(function(hit)
if (hit.Velocity.X > dangervelocity or hit.Velocity.Y > dangervelocity or hit.Velocity.Z > dangervelocity) or (script.Parent.Velocity.X > dangervelocity or script.Parent.Velocity.Y > dangervelocity or script.Parent.Velocity.Z > dangervelocity) then
hit:BreakJoints()
if not hit:FindFirstChildOfClass("BodyVelocity") then
local vel = Instance.new("BodyVelocity", hit)
vel.Velocity = Vector3.new((math.random(-12.5, 12.5)), (math.random(8.75, 18.75)), (math.random(-12.5, 12.5)))
vel.MaxForce = Vector3.new((hit.Mass * (4000 * 1)), (hit.Mass * (4000 * 1)), (hit.Mass * (4000 * 1)))
game:GetService("Debris"):AddItem(vel, 0.05)
end
end
end)
No need to worry, though. I can just repair that code to do the same function but add an inequality to make sure the model name isn’t the shark name… right? Wrong.
(Attempted Fix. Credit to @TestDS.)
local dangervelocity = 10
script.Parent.Touched:Connect(function(hit)
if hit.Parent.Name ~= "Megalodon" and (hit.Velocity.X > dangervelocity or hit.Velocity.Y > dangervelocity or hit.Velocity.Z > dangervelocity) or (script.Parent.Velocity.X > dangervelocity or script.Parent.Velocity.Y > dangervelocity or script.Parent.Velocity.Z > dangervelocity) then
hit:BreakJoints()
if not hit:FindFirstChildOfClass("BodyVelocity") then
local vel = Instance.new("BodyVelocity", hit)
vel.Velocity = Vector3.new((math.random(-12.5, 12.5)), (math.random(8.75, 18.75)), (math.random(-12.5, 12.5)))
vel.MaxForce = Vector3.new((hit.Mass * (4000 * 1)), (hit.Mass * (4000 * 1)), (hit.Mass * (4000 * 1)))
game:GetService("Debris"):AddItem(vel, 0.05)
end
end
end)
If you can help me with this, that will be greatly appreciated!!! All I need is for the sharks to cooperate with each other. I will provide you with info on the shark if requested. Most of what you need to know should be in this screenshot.