Hi guys, I am in a while loop, and I have to update UI.
I am using bindable events to pass new information from local script to local script.
I was wondering firing a bindable event each time
while (wait()) do
would lag.
What are you updating? What kind of information are you showing on the UI? Can’t an event be used here?
I am passing from a LocalScript from a Car to a Car UI.
CarEvents.CarUI.Event:Connect(function(speed,gear,top,p)
script.Parent.Car.pbrake.Visible = p
gear = gear == 0 and "N" or gear < 0 and "R" or gear > 0 and gear
script.Parent.Car.speed.Text = "KM: "..math.floor((speed * 1.097))
script.Parent.Car.gear.Text = gear
local r =(math.floor((speed * 1.097))/top)/2
script.Parent.Car.speed.TextColor3 = Color3.new(1,math.clamp(1-r,0,1),math.clamp(1-r,0,1))
end)
well in loop;
while (true) do
if (script.Parent == nil) then
Events.CarEnter:Fire(false)
break
end
car.Chassis.VehicleSeat.Engine.PlaybackSpeed = math.clamp(Variables.Speed/Variables.TopSpeed-.5,0.07,1.4)
wait()
Variables.Speed = math.floor(car.Chassis.VehicleSeat.Velocity.Magnitude)
Move()
Steer()
Events.CarUI:Fire(Variables.Speed,Variables.CurrentGear,Variables.TopSpeed,Variables.ParkingBrake)
end
What is receiving the event? That could also be an issue.
it’s in the arguments.
speed, gear,top which is max speed, and p is a bool value if p brake is on
Right, but what is connected to the event?
Like, what has CarUI.Event:Connect()
?
a bindable event ._.
dawdd
No, I mean what script is connected to it?
You can use RunService.Stepped
or RunServie.Heartbeat
to fire an event multiple times every frame, if that’s what you’re looking for