so i have a script that lerps camera cframes and i have a function where i can switch certian views and it works but this specific lines of code that wont activate the first line no matter where i put it but code without the wait works perfectly fine.
what im trying to acheave is that at the five seconds it changes to that cframe but it seems to make the first line make it not work but after the wait it goes to that first. im unsure whats wrong with it.
when i remove the wait and the code after wait it works and i swopped if its the part but it was not so.
if Selected == 1 then -- this is true
if s1 == false then -- this is false so it will go through
if AnimationPlaying == false then -- this is also false so it will go through
s1 = true -- this toggles it so that in RenderStepped it will go through once until it is done
Goal = CameraLocations.Panning.CFrame
panspeed = 0.001
FOVGOAL = 35
FOVSPEED = 0.25
wait(5)
Goal = CameraLocations.Panning_area1.CFrame
panspeed = 0.001
FOVGOAL = 50
FOVSPEED = 0.5
s1 = false
end
end
end
There isn’t a error message and I’m unsure what you mean of “add a print of selected” are you saying I should add a print at the statement where the if selected then spot. Because it works perfectly with all of my other ones that don’t have wait() so I’m unsure what your trying. It would most likely be activating like a if statement in a renderstep. Like it’s layed out I put on the above comment. When I get the time I’ll add print to selected when I get the time tho.
Also in the pictures with output it shows what the the value on the right and is 1.
I control it manually and the other functions with the same if statements work. Which led to me think that something is wrong on how I’m approaching it but idk.
Like all puzzles it helps if your have all the bits.
I wanted to know what the value was of the variable Selected as the logic steps taken are dependant on it.
I am trying to help by asking you to do what I would if I had the same setup.
Ok. Thanks for highlighting the problem with me not seeing the value in the picture.
I was not able to see what the GarageCamController was but by deduction its the script and it has the child called Value whose Value is assigned to the variable Selected.
I mentioned the error as there is a line in blue at the bottom of the picture in the output section that mentions a time and Stack End.
That to me implies there was an error message above that in the output.
My further question is what happens if you change the value in the Value?
And finally can you adjust the print(“Step1”) to print(“Step1”,s1).
Do another run please and let me know the results.
To answer the question in what the error is. It’s not from the script it’s from a vehicle script inside it’s viewport wich I still need to remove. When I test I will try to remove those scripts.
So pretty much when I change selected it interrupts and changes the location immediately. I’ll put print values in every step of the process.
I am sorry but I am not able to view the video.
I tried using google viewer but that put me onto a web site that mysecurity system wont let me access.
Could you upload it to YouTube?
I’ve cleaned up your source code a little bit, and added some comment questions/observations in. Can you please help me out with those?
game:GetService('RunService').Stepped:Connect(function()
local Selected = script:WaitForChild("Value").Value
s1 = false
s2 = false
s3 = false
s4 = false
s5 = false
if s1 or s2 or s3 or s4 or s5 then -- This will always return false
AnimationPlaying = true
end
if Selected == 1 then
if not s1 then -- This will always be true
if not AnimationPlaying then -- Where does this variable come from?
s1 = true
Goal = CameraLocations.Panning.CFrame -- Where do you define 'CameraLocations'?
panspeed = 0.001 -- Where are these values used in the rest of the script?
FOVGOAL = 35
FOVSPEED = 0.25
print("Step1")
wait(5)
Goal = CameraLocations.Panning_area1.CFrame
panspeed = 0.001
FOVGOAL = 50
FOVSPEED = 0.5
s1 = false
print("Step2")
end
end
end
end)
Also, here’s a fundamental error - you’re calling this function on Stepped, and then attempting to implement a sort of debounce with the s1 value. The problem is, you’re resetting the s1 value every time you call the function. It’s still going to run every time Stepped fires. I would suggest using a while loop instead that loops every 5 seconds as long as Selected (which you will need to update every time) is equal to 1 and AnimationPlaying (which I’m assuming is originally created elsewhere in the script) is false.
After watching your screen recording, you can clearly see what I’m talking about. It’s running every time on Stepped, which is why your Output gets flooded with messages. Then exactly 5 seconds after you change the value, the camera starts to freak out because the first of those Stepped functions have gotten past the wait(5) line and are attempting to change it to the second set of values, while at the same time new Stepped functions are trying to set it to the first set of values.
I see what you are saying. so what s1 - s5 are is to tell when a animation has been selected but i notice how i set it as to where i made it turn off every step so yeah that would of made it bug.
so that might be my solution. if i take those values out of the Renderstepped and make it as
a local s1 = false instead of s1 will that make it save the value when i change it in the Loop is the question ive done this before but i was not sure why it wasnt writing but maybe i just did it wrong.
all the S1 as i said tells all if a animation is activated and if any of them are selected it will return with animationplay == true
im unsure what is more clean in the script really because it dont realy look that different but.
the camera locations is a group in workspace where i have blocks for locations of the camera’s and get their cframes and lerp to them and the things for pan speed is speed of lerp and for Fov Goal’s is using Tween to do them.
i do notice i forgot one thig in
if s1 or s2 or s3 or s4 or s5 then
AnimationPlaying = true
end
i need to add a else statment
if s1 or s2 or s3 or s4 or s5 then -- tells if a animation is playing in the script
AnimationPlaying = true
else
AnimationPlaying = false
end
so how would i fix that.
Im unsure about it because if i do a while loop it would kind of defeat the purpouse of the animationPlaying if statment.
No, your debounce solution isn’t working at all. Let me suggest something in code:
s1 = false --If these are not inside a function, you don't have to use the local keyword
s2 = false
s3 = false
s4 = false
s5 = false
-- Some other code that will modify the s values
script.Value.Changed:connect(function(property)
if script.Value.Value == 1 then
if s1 or s2 or s3 or s4 or s5 then
AnimationPlaying = true
else
AnimationPlaying = false
end
if not AnimationPlaying then
s1 = true
Goal = CameraLocations.Panning.CFrame
panspeed = 0.001
FOVGOAL = 35
FOVSPEED = 0.25
print("Step1")
wait(5)
Goal = CameraLocations.Panning_area1.CFrame
panspeed = 0.001
FOVGOAL = 50
FOVSPEED = 0.5
s1 = false
print("Step2")
end
end
end)
Some of these values are still probably redundant, but I’ve left everything in just in case you use it elsewhere. You see, this doesn’t need to be fired on every single frame, nor even in a loop. You only really need the code to run when you change the Selected value. Try this out and see if it does what you were expecting.
Alright ill try it when i get to a computer. The reason why i had in renderstepped because im trying to make it react instantly than wait for it to loop through the script and the other script if statements with similar things that instead have no animation sequence reacts better because of it.
works perfectly in renderstep, i never knew there was a way to check if something was changed. i have a question tho. when you said you cleaned my script. is there a method for me to keep a clean script. i know i need to add more comments to keep organized but what do you mean by a clean script.