Hello again, I feel like I post here really often with my small brain.
So I have a phone flashlight system that included battery, the flashlight works fine on local side, but now I need to get it working on the server, I assume I’ll have to use event.
Issue:
I don’t know how to properly use remote yet, and what I’m doing isn’t working, the flashlight works fine on local side, but the server still doesn’t get data.
Workspace:
Local script (Battery)
local IsOn = false
local PhoneDead = false
local BatteryDrainRate = 1
local Battery = 100
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
function Toggle()
if IsOn == true and PhoneDead == false then
IsOn = false
script.Parent.Handle.Tap:Play()
script.Parent.LightPart.SpotLight.Enabled = false
script.Parent.Event:FireServer(IsOn,PhoneDead,Battery) --Flashlight is turned on, phone isn't dead, fire event.
elseif IsOn == false and PhoneDead == false then
IsOn = true
script.Parent.Handle.Tap:Play()
script.Parent.LightPart.SpotLight.Enabled = true
script.Parent.Event:FireServer(IsOn,PhoneDead,Battery) --Flashlight is turned off, phone isn't dead, fire event.
end
end
script.Parent.Activated:Connect(Toggle)
RunService.RenderStepped:Connect(function(DeltaTime)
if IsOn == true and PhoneDead == false then
Battery = Battery - BatteryDrainRate * DeltaTime
script.Parent.Screen.SurfaceGui.Frame.Battery.Level.Size = UDim2.new(Battery/100,0,0,70)
script.Parent.Screen.SurfaceGui.Frame.Battery.Text.Text = math.floor(Battery)
end
end)
RunService.RenderStepped:Connect(function(BatterySystem)
if Battery <= 0 and PhoneDead == false then
IsOn = false
script.Parent.LightPart.SpotLight.Enabled = false
script.Parent.Handle.Vibrate:Play()
script.Parent.Screen.SurfaceGui.Enabled = false
script.Parent.Screen.Material = "Plastic"
script.Parent.Screen.Color = Color3.new(0, 0, 0)
script.Parent.Screen.SurfaceLight.Enabled = false
PhoneDead = true
script.Parent.Event:FireServer(IsOn,PhoneDead,Battery) --The flashlight has died, fire event.
script.Disabled = true
elseif Battery <= 20 and script.Parent.Screen.SurfaceGui.Frame.Battery.Level.BackgroundColor3 ~= Color3.new(1, 0, 0) then
script.Parent.Screen.SurfaceGui.Frame.Battery.Level.BackgroundColor3 = Color3.new(1, 0, 0)
script.Parent.Handle.LowBattery:Play()
end
end)
function BatteryRevive()
IsOn = false
PhoneDead = false
script.Parent.Screen.SurfaceGui.Enabled = true
script.Parent.Screen.SurfaceLight.Enabled = true
script.Parent.Screen.Material = "Neon"
script.Parent.Screen.Color = Color3.new(134, 134, 134)
end
Server script (Server)
function Toggle(IsOn,PhoneDead,Battery)
if IsOn == true and PhoneDead == true and Battery <= 0 then --Flashlight is dead but its still on, turn it off.
script.Parent.LightPart.SpotLight.Enabled = false
elseif IsOn == true and PhoneDead == false and Battery >= 0 then
script.Parent.LightPart.SpotLight.Enabled = true
elseif IsOn == false and PhoneDead == false and Battery >= 0 then
script.Parent.LightPart.SpotLight.Enabled = false
end
end
script.Parent.Event.OnServerEvent:Connect(Toggle)
I want to know how to properly send data to server so I can use it for my flashlight system, other tutorial have been confusing for me and I still don’t know how to do it properly.