#RemoteEvent exhausted while having wait()

164 messages · Page 1 of 1 (latest)

unique anvil
#

I beg someone to help me, i'm firing 4 variables through a remoteEvent but it goes haywire.

fast stream
#

use

#

Unreliableremoteevent thing

unique anvil
#

Hm?

#

WHAT

#

THAT EXISTS?

#

i thought you made that name up lol

fast stream
#

Its probably smth

#

Idk

#

But

unique anvil
#

But how do i do it since ive never heard of it lol

#

Bruh

#

Still the same error

fast stream
#

Just dont make the remote event exhausted then

unique anvil
#

how much more do you want

fast stream
#

0.4

#

Its basically

unique anvil
#

nope

fast stream
#

Like someone calling your name 8 times a second

#

Just let them relaz

unique anvil
#

i cant get those variables from a script i need to send them through a remoteevent

unique anvil
misty gyro
misty gyro
unique anvil
#

Alr

misty gyro
#

Oh that's you again !

unique anvil
#

Yep

#

roblox doesnt want let me to make a game

misty gyro
#

But you upate the battery each heartbeat

#

Dont do that

unique anvil
#

Ohhh

#

Should i just get rid of renderstepped?

misty gyro
#

No

#

Instead, fire the server when the property of the image xhanges

#

You can use GetPropertyChangedSignal

#

On your imagelabel

#

To listen the Image property

#

And also, I highly recommend to create a remote event for each player if your game allows a lot of player to join

unique anvil
#

Singleplayer

#

Like this?

#

Pog

#

it isnt talking anymore

#

Although

#

The light doesnt actually spawn

outer stormBOT
#

studio** You are now Level 8! **studio

misty gyro
#

No

unique anvil
#

This is what should happen but the light doesnt go to that position

#

And it gives 0 errors

#

Paul can you help me?

misty gyro
#

Back

unique anvil
#

So

#

I tried with a script and localscript but still nothing

misty gyro
#

ok so

#

you have

unique anvil
#

Want me to show my explorer?

misty gyro
#
[Heartbeat]
  UpdateBattery()
end)

local function UpdateBatteray(battery)
  local result = nil
  for i = 0, 100, 25 do
    result = batteryImages[i]
    if i >= battery then break end
  end
  imageLabel.Image = result
end
#

this is what you have right ?

#

and then you added

unique anvil
#
function UpdateBattery(battery)
    assert(type(battery) == "number")
    local result = nil
    for i = 0, 100, 25 do
        result = batteryImages[i]
        if i >= battery then break end
    end
    print(math.round(battery), Toggle)
    imageLabel.Image = result
end
#

this

misty gyro
#
[Heartbeat]
  UpdateBattery()
end)

local function UpdateBatteray(battery)
  local result = nil
  for i = 0, 100, 25 do
    result = batteryImages[i]
    if battery ~= 0 then
      positionFlash:FireServer(true, Clone, Mouse, cam)
    else
      positionFlash:FireServer(false, Clone, Mouse, cam)
    end
    if i >= battery then break end
  end
  imageLabel.Image = result
end
misty gyro
misty gyro
#

alright so now

unique anvil
#

i did this ```lua
RunService.RenderStepped:Connect(function()
UpdateBattery(battery)
imageLabel:GetPropertyChangedSignal("Image"):Connect(function()
positionFlashlight:FireServer(Toggle, Mouse, cam)
end)
if Toggle then
battery = math.max(battery - drainRate)
end
end)

misty gyro
#

yes then go back to the old verion

unique anvil
#

Yep

misty gyro
#

we will do something like that

RunService.RenderSteeped:Connect(function()
  if Clone then UpdateBattery(battey) end
end)

local function UpdateBatteray(battery)
  local result = nil
  for i = 0, 100, 25 do
    result = batteryImages[i]
    if i >= battery then break end
  end
  if ImageLabel.Image == result then return end -- We dont need to change the image label
  imageLabel.Image = result
end
#

and then

#
RunService.RenderSteeped:Connect(function()
  if Clone then UpdateBattery(battery) end
end)

imageLabel:GetPropertyChangedSignal("Image"):Connect(function()
  positionFlashlight:FireServer(battery ~= 0, Clone, Mouse, cam)
end)

local function UpdateBattery(battery)
  local result = nil
  for i = 0, 100, 25 do
    result = batteryImages[i]
    if i >= battery then break end
  end
  if ImageLabel.Image == result then return end -- We dont need to change the image label
  imageLabel.Image = result
end
unique anvil
#

Mhm

misty gyro
#

and thats it

#

i may have made some typos

#

but this should work fine

unique anvil
#

um

misty gyro
#

?

unique anvil
#
positionFlashlight:FireServer(battery ~= 0, Mouse, cam)
``` so im firing this but i want to recieve this ```lua
positionFlashlight.OnClientEvent:Connect(function(toggle, cam, Mouse )
misty gyro
#

toggle is supposed to be a true / false ?

unique anvil
#

mhm

#

if its on or off

misty gyro
#

and you expect true and false ?

unique anvil
#

mhm

misty gyro
#

well yes

#

but no

#
positionFlashlight.OnClientEvent:Connect(function(player, toggle, cam, Mouse )
#

by default, your FireServer send the player that triggers it

#

so you should add it

#

and it should work

unique anvil
#

umm nothing is happening ingame nor in output

misty gyro
#

send full code of the local script

unique anvil
#

The one that does the UI stuff

#

or the one that does all of the position

#

Im sending both

#
local cam = workspace.CurrentCamera
local RS = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local Flashlight = RS.Flashlight
local gui = script.Parent
local Brightness = 3
local TS = game:GetService("TweenService")
local battery = 100
local drainRate = 0.0075
local Keybind = Enum.KeyCode.F
local UIS = game:GetService("UserInputService")
local Toggle = false
local Mouse = game.Players.LocalPlayer:GetMouse()
local TI = TweenInfo.new(.1, Enum.EasingStyle.Sine)
local imageLabel = assert(gui:FindFirstChildOfClass("ImageLabel"))
local positionFlashlight = RS.PositionFlashlight
local batteryImages = {
    [0] = "rbxassetid://15657584941",
    [25] = "rbxassetid://15657584759",
    [50] = "rbxassetid://15657584640",
    [75] = "rbxassetid://15657584517",
    [100] = "rbxassetid://15657584407",
}


UIS.InputBegan:Connect(function(Input, p)
    if p then return end
    if Input.KeyCode == Keybind then
        Toggle = not Toggle
    end
end)

RunService.RenderStepped:Connect(function()
    UpdateBattery(battery)
end)

imageLabel:GetPropertyChangedSignal("Image"):Connect(function()
    print('agua')
    positionFlashlight:FireServer(game.Players.LocalPlayer, Toggle, Mouse, cam)
end)

function UpdateBattery(battery)
    local result = nil
    for i = 0, 100, 25 do
        result = batteryImages[i]
        if i >= battery then break end
    end
    if imageLabel.Image == result then return end -- We dont need to change the image label
    imageLabel.Image = result
    print('batata')
end
``` UI ^
#
local RS = game:GetService("ReplicatedStorage")
local positionFlashlight = RS.PositionFlashlight
local Flashlight = RS.Flashlight
local Clone = Flashlight:Clone()
Clone.Parent = game.Players.LocalPlayer.Character
local TS = game:GetService("TweenService")
local TI = TweenInfo.new(.1, Enum.EasingStyle.Sine)

positionFlashlight.OnClientEvent:Connect(function(toggle, Mouse, cam)
    print('hi')
    Clone.Position = cam.CFrame.Position
    TS:Create(Clone, TI, {CFrame = CFrame.lookAt(Clone.Position, Mouse.Hit.Position)}):Play()
    if toggle then
        TS:Create(Clone.SpotLight, TI, {Brightness = 3}):Play()
    else
        TS:Create(Clone.SpotLight, TI, {Brightness = 0}):Play()
    end
end)
``` Positions ^
misty gyro
#

alr

#

and you want it triggers the event when ?

#

when battery change or image changes ?

unique anvil
#

everytime basically

#

since the flashlight has to be in the cameras position

misty gyro
#

like each tick ?

#

or each seconds ?

#

or each what

#

cause "everytime" doesnt really tell me when lol

unique anvil
#

i just want it to be smooth when turning and moving around

#

not choppy

misty gyro
#

you want the spotlight to follow the player mouse ?

unique anvil
#

yeah

misty gyro
#

why do you need to server side this ???

#

since its a 1 player game

unique anvil
#

idk man

#

im dumb

#

oh wait

#

i know why i did serverside

misty gyro
#

?

unique anvil
#

Position is not a valid member of TweenInfo

misty gyro
#

thats normal

unique anvil
#

...

misty gyro
#

show script that does that

unique anvil
#

I had put everything server side T-T

misty gyro
unique anvil
#

Position cannot be assigned to

#

And this error too

misty gyro
#

show the script

#

that was doing that

unique anvil
#

alr

#
local RS = game:GetService("ReplicatedStorage")
local TS = game:GetService("TweenService")
local flashlightUpdate = RS.FlashlightUpdate
local Flashlight = RS.Flashlight
local Clone = Flashlight:Clone()
Clone.Parent = script.Parent

flashlightUpdate.Event:Connect(function(toggle, battery, Clone, TI, Mouse, cam)
    if Clone then
        cam = workspace.CurrentCamera
        Clone.Position = cam.CFrame.Position
        TS:Create(Clone, TI, {CFrame = CFrame.lookAt(Clone.Position, Mouse.Hit.Position)}):Play()
      if toggle then
            TS:Create(Clone.SpotLight, TI, {Brightness = 3}):Play()
        else
            TS:Create(Clone.SpotLight, TI, {Brightness = 0}):Play()
        end
    end    
end)
misty gyro
#

because you sent Clone as the tweeninfo in your event

unique anvil
#

bruh

#

...

#

should i put everything into 1 localscript?

misty gyro
#

bro why just not doing

local Players = game:GetService("Players")
local Tweens = game:GetService("TweenService")
local Run = game:GetService("RunService")

local flashLight = ... -- Instance of your flashlight
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local isEnabled = true -- For when the light is on or off

local battery = 100

mouse.Moved:Connect(function()
  local tween = Tweens:Create(flashLight:FindFirstChildOfClass("SpotLight"), tweenInfo, {
    CFrame = CFrame.lookAt(...) -- To move your light wuth the position u want each mouse movement
  })
  tween:Play()
end)

Run.RenderStepped:Connect(function()
  UpdateBattery(battery)
end)

local function UpdateBattery(battery)
  ...
  if battery == 0 and isEnabled then
    isEnabled = false
    local tween = Tweens:Create(...) -- Brightness to 0 tween
  elseif battery > 0 and not isEnabled then
    local tween = Tweens:Create(...) -- Brightness to 3
  end
end
misty gyro
#

just make it not ugly

unique anvil
#

my code is always spaghetti

misty gyro
#

follow some basic conventions

#
Classes, Service, Functions    => PascalCase
variables                      => camelCase
CONSTANT_VARIABLES             => SCREAMING_SNAKE_CASE

this is the one i use
Example:

local Players = game:GetService("Players") -- service
local Foo = require(...) -- class

local function DoSomething(argument) -- function
  local stuff = ... -- variable
  return stuff
end

local MULTIPLIER = 3 -- variable that will not change
local object = Foo.new(MULTIPLIER) -- class object (variable)
unique anvil
#

UpdateBattery(battery)

Attempted to call a nil value

#

its preset to 100...

misty gyro
unique anvil
#

the code is too long 💀

#
local cam = workspace.CurrentCamera
local RS = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local gui = script.Parent
local Brightness = 3
local Flashlight = RS.Flashlight
local Clone = Flashlight:Clone()
Clone.Parent = script.Parent
local TS = game:GetService("TweenService")
local battery = 100
local drainRate = 0.0075
local Keybind = Enum.KeyCode.F
local UIS = game:GetService("UserInputService")
local Toggle = false
local isEnabled = false
local Mouse = game.Players.LocalPlayer:GetMouse()
local TI = TweenInfo.new(.1, Enum.EasingStyle.Sine)
local imageLabel = assert(gui:FindFirstChildOfClass("ImageLabel"))
local positionFlashlight = RS.PositionFlashlight
local batteryImages = {
    [0] = "rbxassetid://15657584941",
    [25] = "rbxassetid://15657584759",
    [50] = "rbxassetid://15657584640",
    [75] = "rbxassetid://15657584517",
    [100] = "rbxassetid://15657584407",
}


UIS.InputBegan:Connect(function(Input, p)
    if p then return end
    if Input.KeyCode == Keybind then
        Toggle = not Toggle
    end
end)

RunService.RenderStepped:Connect(function()
    UpdateBattery(battery)
end)

Mouse.Moved:Connect(function()
    local tween = TS:Create(Flashlight:FindFirstChildOfClass("SpotLight"), TI, {
        CFrame = CFrame.lookAt(Clone.Position, Mouse.Hit.Position) -- To move your light wuth the position u want each mouse movement
    })
    tween:Play()
end)

imageLabel:GetPropertyChangedSignal("Image"):Connect(function()
    print('agua')
    positionFlashlight:FireServer(game.Players.LocalPlayer, Toggle, Mouse, cam)
end)
#
function UpdateBattery(battery)
    local result = nil
    for i = 0, 100, 25 do
        result = batteryImages[i]
        if i >= battery then break end
    end
    if imageLabel.Image == result then return end -- We dont need to change the image label
    imageLabel.Image = result
    if battery == 0 and isEnabled then
        isEnabled = false
        local tween = TS:Create(Clone.SpotLight, TI, {Brightness = 3}) -- Brightness to 0 tween
    elseif battery > 0 and not isEnabled then
        local tween = TS:Create(Clone.SpotLight, TI, {Brightness = 0}) -- Brightness to 3
    end
end
misty gyro
unique anvil
#

mhm

misty gyro
#

ill check later

unique anvil
misty gyro
#

i rn cant help more

unique anvil
#

alright its fine thanks for helping tho

misty gyro
#

in your case i cant help more

#

i dont have studio on this computer

unique anvil
#

its fine

unique anvil
#

I fixed that error

#

And another error

unique anvil
#

Idk why but renderstepped is bugging

unique anvil
#

@misty gyro I think ill try hardcoding it.

misty gyro
#

alr

unique anvil
#

Since it doesnt want to work

#

Explain how this doesnt work