Hello developers! I am having a problem with client-server data sending. The problem is it’s working pretty slow (delta time about 2 seconds), how can i fasten this? Any tips are acceptable, thank you!
(Remote event used)
Local script:
local menu = script.Parent
local photoCameraBtn = menu.PhotoCameraButton
local toggleCameraBtn = menu.ToggleCameraButton
local plr = game:GetService("Players").LocalPlayer
wait(2)
local captureService = game:GetService("CaptureService")
local tweenService = game:GetService("TweenService")
local UIS = game:GetService("UserInputService")
local TXS = game:GetService("TextChatService")
local mouse = game.Players.LocalPlayer:GetMouse()
local photoSend = game.ReplicatedStorage.Events.Camera.PhotoReceive
local takeCameraEvent = game.ReplicatedStorage.Events.Camera.TakeCamera
local putCameraEvent = game.ReplicatedStorage.Events.Camera.PutCamera
local takeKey = Enum.KeyCode.H
local captureKey = mouse.Button1Down
local mobile
if UIS.KeyboardEnabled == false then
mobile = true
toggleCameraBtn.Visible = true
end
local function Print(Id)
print(Id)
if Id then
print("Ending fires")
photoSend:FireServer(Id)
print("End")
end
end
local function Capture()
captureService:CaptureScreenshot(Print)
end
local function photo()
local camera = plr.Character:FindFirstChild("PlayerCamera")
if camera then
local ready = camera:FindFirstChild("Toggle")
if ready and ready:IsA("BoolValue") then
if ready.Value == true then
Capture()
end
end
end
end
UIS.InputBegan:Connect(function(input, processedEvent)
if input.KeyCode == takeKey then
if not processedEvent then
takeCameraEvent:FireServer()
print("Firing server to take camera")
end
elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
if not processedEvent then
photo()
end
end
end)
toggleCameraBtn.TouchTap:Connect(function()
takeCameraEvent:FireServer()
end)
photoCameraBtn.TouchTap:Connect(photo)
Legacy script:
local model = script.Parent
local belt = model.Belt
local bFront = belt.Torus.Bone
local bLeft = belt.Torus["Bone.002"]
local bRight = belt.Torus["Bone.001"]
local bBack = belt.Torus["Bone.003"]
local animations = game.ReplicatedStorage.Animations
local holdCamera = animations.HoldingCamera
local putCamera = animations.PutCamera
local takeCamera = animations.TakeCamera
local ready = model.Ready
local canTake = model.CanTake
local toggle = model.Toggle
local inAnimation = model.InAnimation
local photoReceive = game.ReplicatedStorage.Events.Camera.PhotoReceive
local takeCameraEvent = game.ReplicatedStorage.Events.Camera.TakeCamera
local putCameraEvent = game.ReplicatedStorage.Events.Camera.PutCamera
local unEvent = game.ReplicatedStorage.Events.CanSeeObject
local toggleGuiEvent = game.ReplicatedStorage.Events.Camera.ToggleGui
local tweenService = game:GetService("TweenService")
local CS = game:GetService("CollectionService")
local handle = model:WaitForChild("Handle")
local sphere = model:WaitForChild("Sphere")
local beltWeld = handle.Belt
local light = model.Cylinder.SpotLight
local screen = model.Screen.Decal
local foundAnomaly = game.ReplicatedStorage.GameInformation.FoundAnomaly
local PressSound = sphere.Press
local FlashSound = sphere.Flash
local PrintSound = sphere.Print
local rustleSound = handle.RustlingSound
local fadePhoto = tweenService:Create(screen, TweenInfo.new(2.795), {Transparency = 0})
local meshes = {}
local weld = handle.Weld
for i,v in pairs(model:GetDescendants()) do
if v:IsA("MeshPart") and v.Transparency <= 1 then
table.insert(meshes,v)
end
end
local function TakeCamera(plr)
if canTake.Value == true and model.Parent.Name ~= "Models" then
local char = plr.Character
print(char.Name)
local hum = char:FindFirstChildOfClass("Humanoid")
if hum then
takeCameraEvent:FireClient(plr)
print("Processing animations and visuals.")
canTake.Value = false
toggle.Value = true
local anim = hum:LoadAnimation(takeCamera)
local anim2 = hum:LoadAnimation(holdCamera)
local anim3 = hum:LoadAnimation(putCamera)
anim2.Looped = true
anim:Play()
inAnimation.Value = true
rustleSound:Play()
anim:GetMarkerReachedSignal("Take"):Wait()
toggleGuiEvent:FireClient(plr, true)
rustleSound:Stop()
anim2:Play()
belt.PrimaryPart.Transparency = 1
weld.Part0 = char.RightHand
beltWeld.Part0 = char.UpperTorso
local cf0 = CFrame.new(0,-model.PrimaryPart.Size.X/2,0) * CFrame.Angles(math.rad(100),math.rad(75),math.rad(180))
weld.C0 = cf0
anim.Ended:Wait()
inAnimation.Value = false
ready.Value = true
canTake.Value = true
local f = coroutine.wrap(function()
local d = takeCameraEvent.OnServerEvent:Connect(function(plr2)
if plr2.Name == plr.Name then
anim2:Stop()
end
end)
end)
f()
else
warn("Couldn't find humanoid.")
end
else
warn("Can't take the camera.")
end
end
local function PutCamera(plr)
local char = plr.Character
print(char.Name)
local hum = char:FindFirstChildOfClass("Humanoid")
if hum and canTake.Value == true then
putCameraEvent:FireClient(plr)
local anim = hum:LoadAnimation(takeCamera)
local anim2 = hum:LoadAnimation(holdCamera)
local anim3 = hum:LoadAnimation(putCamera)
canTake.Value = false
ready.Value = false
toggle.Value = false
anim3:Play()
inAnimation.Value = true
rustleSound:Play()
anim3:GetMarkerReachedSignal("Put"):Wait()
toggleGuiEvent:FireClient(plr, false)
rustleSound:Stop()
belt.PrimaryPart.Transparency = 0
weld.Part0 = char.UpperTorso
local cf0 = CFrame.new(0,0,-char.UpperTorso.Size.Z) * CFrame.Angles(0,math.rad(180),0)
weld.C0 = cf0
anim3.Ended:Wait()
canTake.Value = true
ready.Value = true
end
end
photoReceive.OnServerEvent:Connect(function(plr,id)
if model.Parent.Name == plr.Name and toggle.Value == true then
print("Received photo.")
PressSound:Play()
wait(0.1)
FlashSound:Play()
light.Enabled = true
wait(0.2)
light.Enabled = false
local models = CS:GetTagged("Anomaly")
if models then
for i,v in pairs(models) do
unEvent:FireClient(plr, v.PrimaryPart.Position, v)
unEvent.OnServerEvent:Connect(function(plr, canSee)
if canSee == true then
foundAnomaly.Value = true
warn("Found anomaly")
end
end)
end
end
screen.Transparency = 1
PrintSound:Play()
screen.Texture = id
fadePhoto:Play()
end
end)
takeCameraEvent.OnServerEvent:Connect(function(plr)
print(plr.Name)
if model.Parent.Name == plr.Name then
if toggle.Value == true and canTake.Value == true then
PutCamera(plr)
print("Putting camera")
elseif toggle.Value == false and canTake.Value == true then
TakeCamera(plr)
print("Taking camera")
else
warn(canTake.Value)
end
else
warn("Camera isn't in player "..plr.Name)
end
end)