So I'm trying to make a script that takes the value from one IntValue (We'll call it Value A), process it, and apply it to a different IntValue (Value B). So far the code works, but I have a problem with it speeding up.
As an example, the first time it reads Value A, Value B will increase/decrease by 1 every 0.1 seconds. The second time it reads from Value A, Value B changes every 0.05 seconds (not accurate, but just to give an idea of what's happening).
bin = script.Parent
Thrust = bin.Thrust --This is Value A, where it reads from
Speed = bin.Speed --This is Value B, where it writes to
TopSpeed = 20
-------------------------------------------
function ForwardBack()
while true do
if Thrust.Value == 1 then
if Speed.Value < TopSpeed then
Speed.Value = (Speed.Value+1)
end
elseif Thrust.Value == -1 then
if Speed.Value > (-TopSpeed/2) then
Speed.Value = (Speed.Value-1)
end
elseif Thrust.Value == 0 then
if Speed.Value > 0 then
Speed.Value = (Speed.Value-1)
elseif Speed.Value < 0 then
Speed.Value = (Speed.Value+1)
end
end
wait(0.1) --Here's where the issue is, I think?
end
end
-------------------------------------------
Thrust.Changed:Connect(ForwardBack)
Any idea what might be causing this? I've tried putting waits in each 'Thrust.Value' check but it doesn't change anything.
For reference, here's the script that writes to Thrust.Value.
uis = game:GetService("UserInputService")
bin = script.Parent
Thrust = bin.Thrust
Yaw = bin.Yaw
Alt = bin.Altitude
--------------------------------------------------------------
uis.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.W then
Thrust.Value = (Thrust.Value+1)
end
if Input.KeyCode == Enum.KeyCode.S then
Thrust.Value = (Thrust.Value-1)
end
if Input.KeyCode == Enum.KeyCode.A then
Yaw.Value = (Yaw.Value-1)
end
if Input.KeyCode == Enum.KeyCode.D then
Yaw.Value = (Yaw.Value+1)
end
if Input.KeyCode == Enum.KeyCode.R then
Alt.Value = (Alt.Value+1)
end
if Input.KeyCode == Enum.KeyCode.F then
Alt.Value = (Alt.Value-1)
end
end)
uis.InputEnded:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.W then
Thrust.Value = (Thrust.Value-1)
end
if Input.KeyCode == Enum.KeyCode.S then
Thrust.Value = (Thrust.Value+1)
end
if Input.KeyCode == Enum.KeyCode.A then
Yaw.Value = (Yaw.Value+1)
end
if Input.KeyCode == Enum.KeyCode.D then
Yaw.Value = (Yaw.Value-1)
end
if Input.KeyCode == Enum.KeyCode.R then
Alt.Value = (Alt.Value-1)
end
if Input.KeyCode == Enum.KeyCode.F then
Alt.Value = (Alt.Value+1)
end
end)
--------------------------------------------------------------

1 comment
Thanks for the help! But I do have a question. In general terms, does a 'while true do' loop act in the same way as 'var.Event:connect'?