Jump to content

JoinSound


Adde

Recommended Posts

Hello, I made a script that play a sound on join and then stop it on login. The problem is that the sound don´t start, what´s wrong? Thankfull for answears :)

function playSoundOnJoin() 
    local sound = playSound("scary.mp3") 
    setSoundVolume(sound, 1) 
end 
addEventHandler("onPlayerJoin", root, playSoundOnJoin) 
  
function stopSoundOnLogin() 
stopSound(scary) 
end 
addEvent("stop", true) 
addEventHandler("onPlayerLogin", root, stopSoundOnLogin) 

btw, nothing in debug

Link to comment

I using it as client..

Okay, so like this?

client

addEventHandler( "onClientResourceStart", root, 
function () 
    local sound = playSound("scary.mp3") 
    setSoundVolume(sound, 1) 
    end 
) 
  
function stopSoundOnLogin() 
stopSound(sound) 
end 
addEvent("stop", true) 
addEventHandler("onPlayerLogin", root, stopSoundOnLogin) 

Link to comment

-- Server

  
  
function stopSoundOnLogin() 
    triggerClientEvent(source,"stop",source) 
end 
addEventHandler("onPlayerLogin", root, stopSoundOnLogin) 
  
  

- Client

  
  
  
local sound 
  
addEventHandler( "onClientResourceStart", resourceRoot, 
function () 
      sound = playSound("scary.mp3") 
      setSoundVolume(sound, 1) 
    end 
) 
  
function stopSoundOnLogin() 
    if isElement(sound) then 
        stopSound(sound) 
    end  
end 
addEvent("stop", true) 
addEventHandler("stop", root, stopSoundOnLogin) 
  
  

Link to comment
  • 11 months later...

I know this topic is almost a year old, but my problem is similar to this (at least I searched before posting a new topic?)

Anyways, I'm completely new to Lua and am playing around with making a new RP server from scratch.

You actually taught me how to create and trigger events. Thanks!

I tried using what you have pasted and it does play, however, where you have:

addEventHandler("onPlayerLogin", root, stopSoundOnLogin) 

Mine is:

addEventHandler("spawnCharacter", root, stopSoundOnLogin) 

And it continues to play. I'm having trouble understanding this "addEventHandler" and such. I cannot count how many times i've read the wiki on this and it's like I'm reading Spanish.

If someone could explain this and maybe explain the difference of you putting root rather than getRootElement() or some of the others I see in the Wiki?

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...