I’ve spent about an hour trying to get a model to rotate when a given audio is played, the audio is played using math.random, but thats a seperate script so I don’t think it’s the issue.
I’ve tried multiple variants, even using tweens, but none of it works no matter what I try. The model will rotate fine when its set to “while true do” but once I add in the part where it needs the audio playing to start rotating, it completely breaks with no errors given.Preformatted text
(both attachments gave the same result)
I am very new to scripting, so if I was just completely wrong and missed something my bad
local spinning = script.Parent
local sound = script.Parent.Parent.Sound
sound.Played:Connect(function()
repeat
--// rotate here
task.wait()
until sound.IsPlaying == false
end)
For some reason sound events don’t fire on the server side/they’re unreliable. One thing you can do is to check if the value of TimePosition is actively changing and if it does assume the sound is playing:
local part: BasePart = script.Parent
local sound: Sound = part.Parent:WaitForChild("Sound")
local tp = sound.TimePosition
while task.wait() do
if sound.TimePosition == tp then continue end
tp = sound.TimePosition
part.CFrame *= CFrame.fromEulerAnglesXYZ(0, 0.05, 0)
end
Although I would personally avoid animating parts on the server side, instead I would use a LocalScript that just listens to the events and plays with threads/coroutines. The only negative difference client side code would make is that two clients may see the part rotated at different angles at the same point in time.