I have a script that searches inside a region for players, and applies a client sided camera shake if said players are in the region. Through many trials, the client sided shake seems to apply completely at random, and I can not find any way to consistently replicate it breaking or working.
Server Script:
local EarthFolder = script.Meshes.Earth --Meshes are stored in ServerScriptStorage.Script
local EarthPillar = EarthFolder.EarthPillar:Clone()
local EarthParticle = EarthPillar.ParticleMaker.ParticleEmitter
EarthPillar:SetPrimaryPartCFrame(CFrame.new(Pos) * CFrame.new(0,-7.5,0))
EarthParticle.Parent.CFrame = EarthParticle.Parent.CFrame * CFrame.new(0,10,0)
EarthParticle.Enabled = true
EarthPillar.Parent = game.Workspace:WaitForChild(player.Name.." Effects")
local pos1 = EarthPillar.PrimaryPart.Position - (EarthPillar.PrimaryPart.Size / 2)
local pos2 = EarthPillar.PrimaryPart.Position + (EarthPillar.PrimaryPart.Size / 2)
local Hitbox = Region3.new(pos1, pos2)
for i = 1, 20 do
task.wait(0.05)
local partsInHibox = workspace:FindPartsInRegion3(Hitbox, nil, 20)
print(partsInHibox)
for _, v in pairs(partsInHibox) do
if v.Name == "Head" or v.Name == "Left Arm" or v.Name == "Left Leg" or v.Name == "Right Arm" or v.Name == "Right Leg" or v.Name == "Torso" then
local PlayerTarget = Players:GetPlayerFromCharacter(v.Parent)
print(PlayerTarget)
EarthAttack:FireClient(PlayerTarget, "ScreenShakeTrue") --EarthAttack is a remoteEvent in ReplicatedStorage
else
EarthAttack:FireAllClients("ScreenShakeFalse") --Probably bad practice but was the quickest solution I was able to find, Might be the issue?
end
end
end
Client Script:
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
LocalPlayer.CharacterAdded:Wait()
local Char = LocalPlayer.Character
local Humanoid = Char:WaitForChild("Humanoid")
local Active = false
remoteEarth.OnClientEvent:Connect(function(info) --remoteEarth is same remoteEvent as EarthAttack
if info == "ScreenShakeTrue" then
Active = true
while Active == true do
local x = math.random(-100,100)/90
local y = math.random(-100,100)/90
local z = math.random(-100,100)/90
Humanoid.CameraOffset = Vector3.new(x,y,z)
task.wait()
end
elseif info == "ScreenShakeFalse" then
Active = false
Humanoid.CameraOffset = Vector3.new(0,0,0)
end
end)
Video of bug: https://youtu.be/F1W1KT8wgTA
Any help would be appreciated! A similar thing like this has happened before where seemingly functional code just randomly decides to not work and I was never able to get to the bottom of it Oh and the screenshake persisting after the animation is completed is “intentional”! I have yet to code in a fire for “ScreenShakeFalse” after the animation is completed.