Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Anyone know whats causing this While true loop script to fail?

I've got a while true loop that detects a change in a value and implements that change onto a vehicle seat, It used to work perfectly but now can't seem to detect the change in value. It works while the value is at 0 but once it hits 10 then it doesn't detect that change. I'm abit baffled and another while true loop that detects value changes works perfectly to this day so i'm a tad baffled as to where I've gone wrong, anyways here's the code:

while true do
wait(.5)
	if script.Parent.Accel.Value==0 then
	script.Parent.Parent.VehicleSeat.Torque=0
	end
	
	if script.Parent.Accel.Value==10 then
	script.Parent.Parent.VehicleSeat.Torque=0.3

end
end

The script shares the same parent as the value, so everything is where its supposed to be, its been months of nothing working so any feedback would be highly appreciated, cheers for your time guys!

1 answer

Instead of a while loop you can use a .Changed event

Links to help you learn more:


local Accel = script.Parent.Parent.Accel -- make this a variable for easy access
local VehicleSeat = script.Parent.Parent.VehicleSeat -- make this a variable for easy access

local function Changed(Value) -- Value is the new value of Object Accel

	if Value == 0 then -- Check to see if Value is 0
		VehicleSeat.Torque = 0
	elseif Value == 10 then -- if value does not = 0 then check to see if it = 10
		VehicleSeat.Torque = 0.3
	end

end

Accel.Changed:Connect(Changed) -- Connect Changed function

5 comments

0

I'll give it a try, thanks for the reply!

0

Hasn't seemed to work, had a look at the output and that isn't showing any errors, I'm stumped on what the problem could be lmao

0

Then it has to do with something outside of the code, is the Accel.Value being changed anywhere else in your code?

0

I don't think so, the value changes to 10 as it should when the E key is presses, at that point the script should detect that change and apply the torque to the seat.

0

The accel value itself is changed inside a gui in the seat that the user is sat in, like i said above it all works and does as it should there

This discussion is preserved as it was. New answers, comments, and votes are closed.