Jump to content

Login music


oldnag

Recommended Posts

this is the code i have

function startSound ( ) -- Adding the function 
    playSound ( "music.mp3", false ) 
end 
addEventHandler ( "onClientResourceStart", getResourceRootElement ( getThisResource ( ) ), startSound ) 
function stopMySound() 
    stopSound( sound ) 
end 
addEventHandler ( "onPlayerSpawn", getRootElement() stopMySound ) 

Link to comment

ok i changed to this and still no sound plays

function startSound ( )  
    sound = playSound ( "music.mp3" ) 
end 
addEventHandler ( "onClientResourceStart", getResourceRootElement ( getThisResource ( ) ), startSound ) 
  
function stopMySound() 
    destroyElement( sound ) 
end 
addEventHandler ( "onClientPlayerSpawn", localPlayer() stopMySound ) 
  

Link to comment
addEventHandler ( "onClientPlayerSpawn", localPlayer() stopMySound ) 

That's wrong, should be:

addEventHandler ( "onClientPlayerSpawn", localPlayer, stopMySound ) 

Also, check if the sound exist, because the player won't spawn just once, so, use:

isElement 

to check if the sound element exists before attemp to destroy it.

Link to comment

You got me wrong, I didn't told you to remove destroyElement.

function stopMySound ( ) 
    if isElement ( sound ) then 
        destroyElement ( sound ) 
    end 
end 
addEventHandler ( "onClientPlayerSpawn", localPlayer, stopMySound ) 

Link to comment

ok i tryed that mate but the music still plays after i spawn in

function loginMusic ()  
    local sound = playSound("music.mp3", false) 
    setSoundVolume(sound, 3.2) 
end 
addEventHandler ( "onClientResourceStart", getRootElement(), loginMusic) 
  
function stopMySound ( ) 
    if isElement ( sound ) then 
        destroyElement ( sound ) 
    end 
end 
addEventHandler ( "onClientPlayerSpawn", localPlayer, stopMySound ) 

Link to comment

That's because you made your sound variable local:

local sound = playSound("music.mp3", false) 

Should be:

function loginMusic () 
    sound = playSound("music.mp3", false) 
    setSoundVolume(sound, 3.2) 
end 
addEventHandler ( "onClientResourceStart", resourceRoot, loginMusic) 
  
function stopMySound ( ) 
    if isElement ( sound ) then 
        destroyElement ( sound ) 
    end 
end 
addEventHandler ( "onClientPlayerSpawn", localPlayer, stopMySound ) 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...