What I’m trying to do is make a script that will randomly change the gravity every 10 seconds. But while it is changing the number, I’m not feeling the effect of the gravity change.
gravity = script.Parent.Gravity
while 5 == 5 do
gravity = math.random(10, 200)
print(gravity)
wait(10)
end
sound = game.SoundService.Music -- Declares a music variable
print(“a”) -- Prints out 'a'
while 5 == 5 do -- Checks whether a value is true or not
sound.PlaybackSpeed = math.random(1, 200)/100 -- Changes the playback speed of music by a random amount
print(sound.PlaybackSpeed) -- Prints the playback speed
wait(math.random(1, 10)) -- Waits a random amount of time
end
Going through line by line in the script that you provided, there is no line in there that can possibly change the gravity of your workspace. Like I said before, you can change the gravity by setting workspace.Gravity. You can take a look at the example in the link below for an example of changing the gravity.
I think it’s a very common issue but one that scripters often miss - when you declare a variable such as
local myVariable = myObject.someValue
The variable myVariable keeps that value, and doesn’t affect the original value if it is changed. That’s why in your example when you change gravity to a new value, it only changes the value of gravity, not script.Parent.Gravity.
Instead of that, you could try directly setting script.Parent.Gravity to a random value.