So, i’ve recently made a simple click detector door. It works fine, but it’s very ping dependant. And since it functions using for loops, it can be heavy on the server side. So to fix this i’ve decided to move the function to the client side and run it for all clients to take the load off of the server and make it less ping dependant. But when i do that, simply nothing happens. I don’t have any experience running things on the client side so, can you guys help me figure out what i’m doing wrong?
Here’s the script im running on a LocalScript
-- Variables
dooropen = false
setspeed = 8.5
speed = 8.5
forloopthing = 20
drag = speed / forloopthing
debounce = false
-- Collision disabler
function setcollision(dp, val)
for i, object in ipairs(dp) do
if object:IsA("Part") then
object.CanCollide = val
end
end
end
script.cd.OnClientEvent:Connect(function()
local doorparts = script.Parent:GetChildren()
if debounce == false then
debounce = true
if dooropen == false
dooropen = true
script.Parent.DO:Play()
setcollision(doorparts, false)
-- Door opening animation
for i = 1, forloopthing do
script.Parent:SetPrimaryPartCFrame(script.Parent.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(speed), 0))
speed = speed - drag
wait()
end
setcollision(doorparts, true)
speed = setspeed
elseif dooropen == true then
dooropen = false
script.Parent.DC:Play()
setcollision(doorparts, false)
for i = 1, forloopthing do
script.Parent:SetPrimaryPartCFrame(script.Parent.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(- speed), 0))
speed = speed - drag
wait()
end
setcollision(doorparts, true)
speed = setspeed
end
wait(0.5)
debounce = false
end
end)
And here’s the script i’m using to fire this on the client side.
script.Parent.ClickDetector.MouseClick:Connect(function()
script.Parent.DSC.cd:FireAllClients()
end)
Thanks in advance.