Jump to content

playSound Error


FSXTim

Recommended Posts

Posted

Hello,

I have a problem with my script. When a player press the button XY, a song has to start, but it doesn't.

/debugscript 3 error:

... attempt to call global 'playSound' (a nil value)

client:

function startMusic1 (state) 
    local player = getLocalPlayer() 
    if state == "left" then 
        if source == GUIEditor_Button[13] then 
            triggerServerEvent("Music1", getLocalPlayer(), player)  
        end 
    end 
end  
addEventHandler("onClientGUIClick", getRootElement(), startMusic1) 

server:

function Music1 (player) 
    local name = getPlayerName(player) 
    song = playSound("everything.mp3", false) 
    setSoundVolume(song, 1) 
    outputChatBox(name.." hat den Party-Knopf gedrückt!", getRootElement(), 0, 255, 255) 
end 
addEvent("Music1", true) 
addEventHandler("Music1", getRootElement(), Music1)  

Can anybody help me, please?

Greets

Posted

Show us your meta.xml. Your must set the file (song) in this file. You did it? Something like this:

<file src="everything.mp3" /> 
<script src="server.lua" type="server" /> 
<script src="client.lua" type="client" /> 

Oh, and please: show us your directory structure. If you have something like this:

/MyGamemode/scripts/server.lua 

/MyGamemode/scripts/everything.mp3 

/MyGamemode/meta.xml 

You must set, in code, the complete structure:

playSound("scripts/everything.mp3", false) 

And remember: no double posts.

Posted

Thanks for your answer.

meta.xml

        "music\everything.mp3" /> 
    

directory:

gamemode/shop_client 
gamemode/shop_server 
gamemode/music/everything 
gamemode/meta.xml 

I will try it like this:

1.playSound("music/everything.mp3", false) 

Greets

Posted

Thanks for your help, sir!

I did it like this:

client:

function startMusic1 (state) 
    local player = getLocalPlayer() 
    if state == "left" then 
        if source == GUIEditor_Button[13] then 
            triggerServerEvent("Music1", getLocalPlayer(), player)  
        end 
    end 
end  
addEventHandler("onClientGUIClick", getRootElement(), startMusic1) 

server:

function Music1 (player) 
    local name = getPlayerName(player) 
    song = playSound("music/everything.mp3", false) 
    setSoundVolume(song, 1) 
    outputChatBox(name.." hat den Party-Knopf gedrückt!", getRootElement(), 0, 255, 255) 
end 
addEvent("Music1", true) 
addEventHandler("Music1", getRootElement(), Music1)  

Still not working. Same error:

server_shop.lua:3: attempt to call global 'playSound' (a nil value)

Greets

Posted

The playSound() function is usable only in client-side.

Client-side

function startMusic1 (state) 
    local player = getLocalPlayer() 
    if state == "left" then 
        if source == GUIEditor_Button[13] then 
            local song = playSound("music/everything.mp3", false) 
            setSoundVolume(song, 1) 
            triggerServerEvent("Music1", getLocalPlayer(), player) 
        end 
    end 
end  
addEventHandler("onClientGUIClick", getRootElement(), startMusic1) 

Server-side

    function Music1 (player) 
        local name = getPlayerName(player) 
        outputChatBox(name.." hat den Party-Knopf gedrückt!", getRootElement(), 0, 255, 255) 
    end 
    addEvent("Music1", true) 
    addEventHandler("Music1", getRootElement(), Music1) 

Posted

That's wrong FSXTim, you have to trigger to the client side again.

-- client side:

function startMusic1 ( state ) 
    if ( state == "left" ) then 
        if ( source == GUIEditor_Button[13] ) then 
            triggerServerEvent ( "Music1", localPlayer ) 
        end 
    end 
end  
addEventHandler ( "onClientGUIClick", getRootElement(), startMusic1 ) 
  
addEvent ( "playTheSound", true ) 
addEventHandler ( "playTheSound", root, 
    function ( ) 
        song = playSound ( "music/everything.mp3", false ) 
        setSoundVolume ( song, 1 ) 
    end 
) 

-- server side:

function Music1 ( ) 
    local name = getPlayerName ( source ) 
    outputChatBox ( name.." hat den Party-Knopf gedrückt!", getRootElement(), 0, 255, 255 ) 
    triggerClientEvent ( "playTheSound", root ) 
end 
addEvent ( "Music1", true ) 
addEventHandler ( "Music1", getRootElement(), Music1 ) 

Posted
    function() 
        local sWidth, sHeight = guiGetScreenSize() 
        local px = sWidth/1920 
        local py = sHeight/1080 

Still having the same problem as before.

Need help, please!

Greets

Posted

I'm using the guieditor. But when I mark relativ, it won't relative the texts, buttons and edits, will it? (Only the window, eh?)

Greets

Posted

Now I did it like this:

Default screen output type:

[X] Relative

[ ] Absolute

Default child output type:

[X] Relative

[ ] Absolute

Correct?

And by the way, thanks for your help, sir!

Posted

Ok, that's working, but can you please help me with teamviewer? Please, I need your help, there is still one problem.

Greets

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