Jump to content

triggerclientevent Problem


Mersad

Recommended Posts

Hello!
Do you know what the problem is?

--Server Side
function VoteSystem(title)
	outputChatBox("Ghor'e Keshi Shodu Shod! Ba Dasture [/sherkat] Dar Ghore Keshi Sherkat Konid!")
end
addEvent("ElameShorueGhore", true)
addEventHandler("ElameShorueGhore", resourceRoot, VoteSystem)


function getrp( source, commandName )
	randomP = getRandomPlayer()
	triggerClientEvent(source, "getRandPlayer", source, randomP)
end
addEvent("StartRandom", true)
addEventHandler("StartRandom", resourceRoot, getrp)
--Client Side (Summarized)
function dxUI(randomP)
    ui["BG"] = dxDrawImage(x*741,0,x*619,y*487,"files/BG.png")
    ui["title"] = dxDrawText(title, 0, y*70, x*1340, 0, tocolor(255, 255, 255, 255), 1, titleFont, "right")
    ui["playerWon"] = dxDrawText(tostring(getPlayerName(randomP)), x*860, y*242,0,0, tocolor(255, 255, 255, 255), 1, playerFont)
end
addEvent("getRandPlayer", true)
addEventHandler("getRandPlayer", root, dxUI)

function ghore(CMD, ...)
    if (ghoreStatus == 0) then
        ghoreStatus = 1
        local EnteredTitle = table.concat ( { ... }," " )
        title = tostring(EnteredTitle)
        addEventHandler("onClientRender", getRootElement(), dxUI)
        triggerServerEvent("ElameShorueGhore", root)
        triggerServerEvent("StartRandom", root)
    end
end
addCommandHandler("ghore", ghore)

I keep getting this warning in debugscript:

Warning: ghore\server.lua:10: Bad argument @'triggerClientEvent' [Expected string at argument 1, got nil]

Warning: ghore\client.lua:19: Bad argument @'getPlayerName' [Expected player at argument 1, got nil]

Warning: ghore\client.lua:19: Bad argument @'getPlayerName' [Expected player at argument 1, got nil] [DUP x214]

Warning: ghore\client.lua:19: Bad argument @'getPlayerName' [Expected player at argument 1, got nil] [DUP x215]

Edited by Mersad
Link to comment
--Server Side
function getrp()
	local randomP = getRandomPlayer()
	triggerClientEvent(source, "getRandPlayer", source, randomP)
end
addEvent("StartRandom", true)
addEventHandler("StartRandom", resourceRoot, getrp)
--Client Side
function dxUI(randomP)
    ui["BG"] = dxDrawImage(x*741,0,x*619,y*487,"files/BG.png")
    ui["title"] = dxDrawText(title, 0, y*70, x*1340, 0, tocolor(255, 255, 255, 255), 1, titleFont, "right")
    ui["playerWon"] = dxDrawText(tostring(getPlayerName(randomP)), x*860, y*242,0,0, tocolor(255, 255, 255, 255), 1, playerFont)
end
addEvent("getRandPlayer", true)
addEventHandler("getRandPlayer", root, dxUI)

function ghore(CMD, ...)
    if (ghoreStatus == 0) then
        ghoreStatus = 1
        local EnteredTitle = table.concat ( { ... }," " )
        title = tostring(EnteredTitle)
        addEventHandler("onClientRender", getRootElement(), dxUI)
        triggerServerEvent("ElameShorueGhore", root)
        triggerServerEvent("StartRandom", root)
    end
end
addCommandHandler("ghore", ghore)

 

Link to comment
2 hours ago, Mersad said:

Hello!
Do you know what the problem is?

--Server Side
function VoteSystem(title)
	outputChatBox("Ghor'e Keshi Shodu Shod! Ba Dasture [/sherkat] Dar Ghore Keshi Sherkat Konid!")
end
addEvent("ElameShorueGhore", true)
addEventHandler("ElameShorueGhore", resourceRoot, VoteSystem)


function getrp( source, commandName )
	randomP = getRandomPlayer()
	triggerClientEvent(source, "getRandPlayer", source, randomP)
end
addEvent("StartRandom", true)
addEventHandler("StartRandom", resourceRoot, getrp)
--Client Side (Summarized)
function dxUI(randomP)
    ui["BG"] = dxDrawImage(x*741,0,x*619,y*487,"files/BG.png")
    ui["title"] = dxDrawText(title, 0, y*70, x*1340, 0, tocolor(255, 255, 255, 255), 1, titleFont, "right")
    ui["playerWon"] = dxDrawText(tostring(getPlayerName(randomP)), x*860, y*242,0,0, tocolor(255, 255, 255, 255), 1, playerFont)
end
addEvent("getRandPlayer", true)
addEventHandler("getRandPlayer", root, dxUI)

function ghore(CMD, ...)
    if (ghoreStatus == 0) then
        ghoreStatus = 1
        local EnteredTitle = table.concat ( { ... }," " )
        title = tostring(EnteredTitle)
        addEventHandler("onClientRender", getRootElement(), dxUI)
        triggerServerEvent("ElameShorueGhore", root)
        triggerServerEvent("StartRandom", root)
    end
end
addCommandHandler("ghore", ghore)

I keep getting this warning in debugscript:

Warning: ghore\server.lua:10: Bad argument @'triggerClientEvent' [Expected string at argument 1, got nil]

Warning: ghore\client.lua:19: Bad argument @'getPlayerName' [Expected player at argument 1, got nil]

Warning: ghore\client.lua:19: Bad argument @'getPlayerName' [Expected player at argument 1, got nil] [DUP x214]

Warning: ghore\client.lua:19: Bad argument @'getPlayerName' [Expected player at argument 1, got nil] [DUP x215]

Heyo Bro! You need to pass the localPlayer in the trigger, because the source does not exist on the server-side

--Server Side
function VoteSystem(title)
	outputChatBox("Ghor'e Keshi Shodu Shod! Ba Dasture [/sherkat] Dar Ghore Keshi Sherkat Konid!")
end
addEvent("ElameShorueGhore", true)
addEventHandler("ElameShorueGhore", resourceRoot, VoteSystem)


function getrp( source, commandName )
	randomP = getRandomPlayer()
	triggerClientEvent(source, "getRandPlayer", source, randomP)
end
addEvent("StartRandom", true)
addEventHandler("StartRandom", resourceRoot, getrp)

-- Client Side
function dxUI(randomP)
    ui["BG"] = dxDrawImage(x*741,0,x*619,y*487,"files/BG.png")
    ui["title"] = dxDrawText(title, 0, y*70, x*1340, 0, tocolor(255, 255, 255, 255), 1, titleFont, "right")
    ui["playerWon"] = dxDrawText(tostring(getPlayerName(randomP)), x*860, y*242,0,0, tocolor(255, 255, 255, 255), 1, playerFont)
end
addEvent("getRandPlayer", true)
addEventHandler("getRandPlayer", root, dxUI)

function ghore(CMD, ...)
    if (ghoreStatus == 0) then
        ghoreStatus = 1
        local EnteredTitle = table.concat ( { ... }," " )
        title = tostring(EnteredTitle)
        addEventHandler("onClientRender", getRootElement(), dxUI)
        triggerServerEvent("ElameShorueGhore", root)
        triggerServerEvent("StartRandom", root, localPlayer)
    end
end
addCommandHandler("ghore", ghore)


 

18 minutes ago, Kidzonio said:

Heyo Bro! You need to pass the localPlayer in the trigger, because the source does not exist on the server-side

--Server Side
function VoteSystem(title)
	outputChatBox("Ghor'e Keshi Shodu Shod! Ba Dasture [/sherkat] Dar Ghore Keshi Sherkat Konid!")
end
addEvent("ElameShorueGhore", true)
addEventHandler("ElameShorueGhore", resourceRoot, VoteSystem)


function getrp( source, commandName )
	randomP = getRandomPlayer()
	triggerClientEvent(source, "getRandPlayer", source, randomP)
end
addEvent("StartRandom", true)
addEventHandler("StartRandom", resourceRoot, getrp)

-- Client Side
function dxUI(randomP)
    ui["BG"] = dxDrawImage(x*741,0,x*619,y*487,"files/BG.png")
    ui["title"] = dxDrawText(title, 0, y*70, x*1340, 0, tocolor(255, 255, 255, 255), 1, titleFont, "right")
    ui["playerWon"] = dxDrawText(tostring(getPlayerName(randomP)), x*860, y*242,0,0, tocolor(255, 255, 255, 255), 1, playerFont)
end
addEvent("getRandPlayer", true)
addEventHandler("getRandPlayer", root, dxUI)

function ghore(CMD, ...)
    if (ghoreStatus == 0) then
        ghoreStatus = 1
        local EnteredTitle = table.concat ( { ... }," " )
        title = tostring(EnteredTitle)
        addEventHandler("onClientRender", getRootElement(), dxUI)
        triggerServerEvent("ElameShorueGhore", root)
        triggerServerEvent("StartRandom", root, localPlayer)
    end
end
addCommandHandler("ghore", ghore)


 

I redid the code, code below

 

--Server Side

local rPlayer 

function getrp( source, commandName )
	randomP = getRandomPlayer()
	rPlayer = randomP
end
addEvent("StartRandom", true)
addEventHandler("StartRandom", root, getrp)

addCommandHandler('ghore',
	function(player, cmd, ...)
		if ghoreStatus == 0 then
			ghoreStatus = 1
			local EnteredTitle = table.concat ( { ... }," " )
			title = tostring(EnteredTitle)
			triggerEvent("StartRandom", root, localPlayer)
			outputChatBox("Ghor'e Keshi Shodu Shod! Ba Dasture [/sherkat] Dar Ghore Keshi Sherkat Konid!")
			if rPlayer and title then
				triggerClientEvent(root, 'receptRender', root, rPlayer, title)
			end
		end
	end
)

-- Client Side

local randomP
local title

function dxUI()
    --dxDrawImage(741,0,619,487,"files/BG.png")
    dxDrawText(title, 0, 70, 1340, 0, tocolor(255, 255, 255, 255), 1, 'default', "right")
    dxDrawText(tostring(getPlayerName(randomP)), 860, 242,0,0, tocolor(255, 255, 255, 255), 1, 'default')
end

function receptRender(rp, tt)
    randomP = rp
    title = tt
    addEventHandler('onClientRender', root, dxUI)
end
addEvent('receptRender', true)
addEventHandler('receptRender', root, receptRender)

 

  • Thanks 1
Link to comment

either source or randomP is nil in the following lines:

triggerClientEvent(source, "getRandPlayer", source, randomP)

and

ui["playerWon"] = dxDrawText(tostring(getPlayerName(randomP)), x*860, y*242,0,0, tocolor(255, 255, 255, 255), 1, playerFont)

You need to make sure that source and randomP are valid player elements before using them.

Edited by FLUSHBICEPS
Link to comment
On 12/02/2023 at 19:18, Kidzonio said:

Heyo Bro! You need to pass the localPlayer in the trigger, because the source does not exist on the server-side

--Server Side
function VoteSystem(title)
	outputChatBox("Ghor'e Keshi Shodu Shod! Ba Dasture [/sherkat] Dar Ghore Keshi Sherkat Konid!")
end
addEvent("ElameShorueGhore", true)
addEventHandler("ElameShorueGhore", resourceRoot, VoteSystem)


function getrp( source, commandName )
	randomP = getRandomPlayer()
	triggerClientEvent(source, "getRandPlayer", source, randomP)
end
addEvent("StartRandom", true)
addEventHandler("StartRandom", resourceRoot, getrp)

-- Client Side
function dxUI(randomP)
    ui["BG"] = dxDrawImage(x*741,0,x*619,y*487,"files/BG.png")
    ui["title"] = dxDrawText(title, 0, y*70, x*1340, 0, tocolor(255, 255, 255, 255), 1, titleFont, "right")
    ui["playerWon"] = dxDrawText(tostring(getPlayerName(randomP)), x*860, y*242,0,0, tocolor(255, 255, 255, 255), 1, playerFont)
end
addEvent("getRandPlayer", true)
addEventHandler("getRandPlayer", root, dxUI)

function ghore(CMD, ...)
    if (ghoreStatus == 0) then
        ghoreStatus = 1
        local EnteredTitle = table.concat ( { ... }," " )
        title = tostring(EnteredTitle)
        addEventHandler("onClientRender", getRootElement(), dxUI)
        triggerServerEvent("ElameShorueGhore", root)
        triggerServerEvent("StartRandom", root, localPlayer)
    end
end
addCommandHandler("ghore", ghore)


 

I redid the code, code below

 

--Server Side

local rPlayer 

function getrp( source, commandName )
	randomP = getRandomPlayer()
	rPlayer = randomP
end
addEvent("StartRandom", true)
addEventHandler("StartRandom", root, getrp)

addCommandHandler('ghore',
	function(player, cmd, ...)
		if ghoreStatus == 0 then
			ghoreStatus = 1
			local EnteredTitle = table.concat ( { ... }," " )
			title = tostring(EnteredTitle)
			triggerEvent("StartRandom", root, localPlayer)
			outputChatBox("Ghor'e Keshi Shodu Shod! Ba Dasture [/sherkat] Dar Ghore Keshi Sherkat Konid!")
			if rPlayer and title then
				triggerClientEvent(root, 'receptRender', root, rPlayer, title)
			end
		end
	end
)

-- Client Side

local randomP
local title

function dxUI()
    --dxDrawImage(741,0,619,487,"files/BG.png")
    dxDrawText(title, 0, 70, 1340, 0, tocolor(255, 255, 255, 255), 1, 'default', "right")
    dxDrawText(tostring(getPlayerName(randomP)), 860, 242,0,0, tocolor(255, 255, 255, 255), 1, 'default')
end

function receptRender(rp, tt)
    randomP = rp
    title = tt
    addEventHandler('onClientRender', root, dxUI)
end
addEvent('receptRender', true)
addEventHandler('receptRender', root, receptRender)

 

Thanks Bro! It Works

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