Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Displaying a sound's current time state?

Asked by
Troidit 253 Moderation Voter
9 years ago

What I'm trying to do is display the current time position of a song/audio I have on a surfaceGUI, it plays it fine, but I can't find out how to display the current time inside the song. (e.g. say the song is halfway through and it is 60 seconds long, the text box would say 30)

local Song = game.Soundscape.Centuries -- Centuries is an already made sound in the Soundscape
local Myself = script.Parent

while Song:IsPlaying() do -- while the song Centuries is playing, do this.
    Myself.Text = Song.TimePosition -- Displays the time on the text
    wait(1) --To prevent lag
end

Currently the script is having a problem with Song:IsPlaying(). the Output states: Attempt to call method IsPlaying (a boolean value)

What am I doing wrong? Is there an easier way to do what I'm trying to do? (Sorry if this seems a tiny bit sloppy, this is my first question posted).

Edited:

wait(1) --To wait for client to load.
local Song = game.Soundscape.Centuries -- Centuries is an already made sound in the Soundscape
local Myself = script.Parent

while Song.IsPlaying do -- while the song Centuries is playing, do this.
    print("I've gotten into the while script!")
    Myself.Text = Song.TimePosition -- Displays the time on the text
    wait(1) --To prevent lag
end

Says nothing and does nothing now that I've fixed it to this.

0
I posted a new comment to help you. The problem is it's .IsPlaying not :IsPlaying FearMeIAmLag 1161 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

This is a simple fix. IsPlaying is a property of a sound object not a method. In order to fix this you would change the line in the script to:

while Song.IsPlaying do

A sound object has many properties including TimePosition, IsPlaying and IsPaused. Methods that can be passed over a sound object include :Play() and :Stop(). A property is a state of an object which can be read and in some cases written to. A method will act upon the object and cause something to happen to it. With :Play(), it will invoke the sound object to begin playing.

EDIT:

I was able to get this to work. The Soundscape is no longer a thing apparently, it is now SoundService.

wait(1) --wait for client stuff to load, not noticeable by player
local song = game.SoundService.Sound
local me = script.Parent

while song.IsPlaying do
    me.Text = song.TimePosition
    wait(1)
end
0
Thanks for the explanation, but I am still having problems with the script, the output NOW states: function arguments expected near 'do' I am now completely lost on what's wrong. I am going to feel very sad if this is an easy fix. Troidit 253 — 9y
0
I have edited my answer and it works for me. Wasn't a bad issue but one that I didn't even realize until now. FearMeIAmLag 1161 — 9y
0
Well, thanks for the wait idea, but I still can't figure out what's wrong with the actual script? (A screenshot of my script&It's location: http://prntscr.com/7k4ih9) Troidit 253 — 9y
0
It's .IsPlaying not :IsPlaying FearMeIAmLag 1161 — 9y
0
It still doesn't seem to help. It got rid of the problem with "Function Arguments Expected near do" but it doesn't really do anything anymore. I put a print string right at the beginning of the While commands, it says them, but doesn't execute the actual thing. Troidit 253 — 9y
Ad

Answer this question