I was recently trying to recreate my own version of Idle Breakout (an idle version of Atari Breakout) in Roblox Studios.
I ran into some issues with the client not properly syncing with what the server is showing when I was trying to make the balls destroy bricks. For some reason, on the client’s side, the bricks get destroyed before you can see the ball’s bouncing off of them.
(You can see network ownership in this video, Network Ownership | Documentation - Roblox Creator Hub)
On the server’s side, the bricks get destroyed when the ball bounces off of them.
This script is inside of the ball:
local ball = script.Parent.Parent --script inside a folder in the ball
ball.Touched:Connect(function(otherPart)
if otherPart:HasTag("Brick") then
--Get config with stats
local config = script.Parent.Parent.BallStats
--Check if the brick will be destroyed
if otherPart.Stats.Health.Value-config.Damage.Value < 0 then
local moneyPerDamage = config.Money.Value/config.Damage.Value
local damage = otherPart.Stats.Health.Value
otherPart.Stats.Health.Value = 0
workspace.Stats.MainStats.Money.Value += math.ceil(moneyPerDamage*damage)
else
otherPart.Stats.Health.Value -= config.Damage.Value+10
workspace.Stats.MainStats.Money.Value += config.Money.Value
end
--Fire Events (for special balls)
script.Parent.BrickEvent:Fire()
script.Parent.BounceEvent:Fire()
--Give the ball velocity
local dist = math.abs((script.Parent.Parent.Position-otherPart.Position).Magnitude)
local offset = script.Parent.Parent.Position-otherPart.Position
local velocity = offset/dist*config.Bounce.Value*30
script.Parent.Parent.Velocity = velocity
elseif otherPart:HasTag("Wall") then
--Get config with stats
local config = script.Parent.Parent.BallStats
--Fire Events (for special balls)
script.Parent.WallEvent:Fire()
script.Parent.BounceEvent:Fire()
--Give the ball velocity
local dist = math.abs((script.Parent.Parent.Position-otherPart.Position).Magnitude)
local offset = script.Parent.Parent.Position-otherPart.Position
local velocity = offset/dist*config.Bounce.Value*30
script.Parent.Parent.Velocity += velocity
end
end)
And this script is inside of the brick (to determine when the brick should be destroyed):
script.Parent.Parent.Stats.Health:GetPropertyChangedSignal("Value"):Connect(function() --script inside a folding inside the brick
if script.Parent.Parent.Stats.Health.Value <= 0 then
workspace.Stats.MainStats.BricksDestroyed.Value += 1
local soundClone = workspace.Sounds.BrickBreak:Clone()
soundClone.Parent = game.SoundService
soundClone:Play()
script.Parent.Parent:Destroy()
task.wait(soundClone.TimeLength)
soundClone:Destroy()
end
end)
I tried making the ball destroy the brick instead of a separate code but that didn’t change it visually.
I also tried forcing the player to have network ownership over the ball but it seemed to break the velocity that the ball is given when bouncing off of the bricks.
This is my first time posting here, so if there are any mistakes I apologise!