I have been working on a roblox game that is meant to play similarly to the multiplayer gamemode in Bomberman 64, and that includes picking up and throwing bombs.
When a player tries to pick up a bomb, the server will move the bomb a few studs in the direction of their UpperTorso’s lookVector, and then weld the bomb to the player’s torso using a WeldConstraint. The bomb itself is just a massless sphere that has its collisions disabled, but is also welded to a a second, massless, completely transparent sphere with its collisions enabled and a defined non-changing size of 3, which acts as the bomb’s collider. The collider is in a CollisionGroup to ignore collisions between it, other bombs, and players. The purpose of the collider is to prevent players from picking up a bomb and clipping it through a wall.
The reason why I have a separate part for the bomb and the collider is so I can change the apparent size of the bomb without affecting the collider. The need to be able change the size of the bomb is in order to make it appear as if the bomb is pulsing:
The collisions work fine if I change the size of the bomb using a script.
This is done using the following code inside of a script parented under the bomb.
local bomb = script.Parent;
local growing = false;
local bombsizeBig = {};
bombsizeBig.Size = bomb.Size*1.1;
local bombsizeSmall = {};
bombsizeSmall.Size = bomb.Size*.9; --reason why I declared bombsizeBig and small like this was because I initially used a tween
--but decided against it since the size could change faster than the tween completed
function pulse()
local size = bomb:FindFirstChild("Size").Value; --Size is a Vector3 Value attached to the bomb.
bombsizeBig.Size = size*1.1;
bombsizeSmall.Size = size*.9;
if growing then
bomb.Size = bomb.Size + Vector3.new(.05,.05,.05);
if bomb.Size.X >= bombsizeBig.Size.X then
growing = false;
end
else
bomb.Size = bomb.Size - Vector3.new(.05,.05,.05);
if bomb.Size.X <= bombsizeSmall.Size.X then
growing = true;
end
end
end
game:GetService("RunService").Heartbeat:Connect(pulse);
The collider will stay the same size even as the bomb’s size varies. It also works perfectly fine if the bomb’s size isn’t changed:
But it seems to break things if I dare change the bomb’s size using a LocalScript:
Using the following code located in a LocalScript under StarterPlayerScripts
--this function will be run on every bomb in the workspace every time RenderStepped fires.
local function pulseBomb(bom)
local tval = bom:FindFirstChild("Growing");
if not tval then
tval = Instance.new("BoolValue");
tval.Name = "Growing";
tval.Value = true;
tval.Parent = bom;
end
local size = bom:FindFirstChild("Size").Value;
local bombsizeBigSize = size*1.1;
local bombsizeSmallSize = size*.9;
if tval.Value then
bom.Size = bom.Size + Vector3.new(.05,.05,.05);
if bom.Size.X >= bombsizeBigSize.X then
tval.Value = false;
end
else
bom.Size = bom.Size - Vector3.new(.05,.05,.05);
if bom.Size.X <= bombsizeSmallSize.X then
tval.Value = true;
end
end
end
Has anyone come across a similar issue and was able to fix it?
Also as a quick sidenote, the server-sided script “solution” is unusable as is since it comes with its own problems that the LocalScript solution doesn’t, only concerning player replication instead of player collisions.