kieran Posted October 9, 2017 Share Posted October 9, 2017 Hello, I made a simple script to play a sound when my player renders, but I want to stop the sound when the player logs in and can't find out how. Client function PlayLoginSound() local sound = playSound("sounds/2.mp3", true) --Play wasted.mp3 from the sounds folder if (sound) then setSoundVolume(sound, 0.5) -- set the sound volume to 50% else return end end addEventHandler ( "onClientResourceStart", root, PlayLoginSound) function StopLoginSound() stopSound(sound) end addEvent("stoploginsound", true) addEventHandler("stoploginsound", getRootElement(), StopLoginSound) Server --Stop login sound function PlayLogin() triggerClientEvent(source, "stoploginsound") end addEventHandler("onPlayerLogin", root, PlayLogin) Any help would be nice, tried triggering client event from server when player logs in, but keeps playing even if it's not looped... Link to comment
DNL291 Posted October 9, 2017 Share Posted October 9, 2017 local variables aren't accessible outside the function. Also, replace 'root' with 'resourceRoot' in event "onClientResourceStart". Link to comment
kieran Posted October 9, 2017 Author Share Posted October 9, 2017 20 minutes ago, DNL291 said: local variables aren't accessible outside the function. Also, replace 'root' with 'resourceRoot' in event "onClientResourceStart". So just remove the local from when I create the sound or put the local variable outside the function to allow me to stop it with the triggerClientEvent? Link to comment
kieran Posted October 9, 2017 Author Share Posted October 9, 2017 This has been solved, it was rather simple actually This: addEventHandler("stoploginsound", getRootElement(), StopLoginSound) Should of been this: addEventHandler("stoploginsound", root, StopLoginSound) And finally for my server side code, this: triggerClientEvent(source, "stoploginsound") Should of been this: triggerClientEvent(source, "stoploginsound", source) Hope this will help people that struggle with stopSound. Link to comment
koragg Posted October 9, 2017 Share Posted October 9, 2017 getRootElement() is the same as root btw. 1 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now