Help needed wit /weapon script

First of all good day to you all people!

My script that ive made doesnt work ingame.
the script is as followed:
Client sided,

RegisterNetEvent('Rpg')
RegisterNetEvent('Ak')
RegisterNetEvent('Sniper')

AddEventHandler('Rpg', function(number) --I also added the argument here
	GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("weapon_rpg"), 1000, true)
	drawNotification(tostring(number))
end)
AddEventHandler('Ak', function(number) --I also added the argument here
	GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("weapon_assaultrifle"), 1000, true)
	drawNotification(tostring(number))
end)
AddEventHandler('Sniper', function(number) --I also added the argument here
	GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("weapon_heavysniper"), 100, true)
	drawNotification(tostring(number))
end)

function drawNotification(text) --Just Don't Edit!
	SetNotificationTextEntry("STRING")
	AddTextComponentString(text)
	DrawNotification(false, false)
end

And server sided,

AddEventHandler('chatMessage', function(source, n, msg)
	local Message = string.lower(msg)
	local MessageParts = stringsplit(Message, " ") --The Seperator Is A Blank Space 
	if (MessageParts[1] == "/weapon") then
		TriggerClientEvent('Rpg', source, MessageParts["rpg"]) --I added the second Argument, the **2** from the message
		TriggerClientEvent('Ak', source, MessageParts["ak"]) --I added the second Argument, the **2** from the message
		TriggerClientEvent('Sniper', source, MessageParts["sniper"]) --I added the second Argument, the **2** from the message
		CancelEvent()
	end
end)

function stringsplit(inputstr, sep)
	if sep == nil then
			sep = "%s"
	end
	local t={} ; i=1
	for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
			t[i] = str
			i = i + 1
	end
	return t
end

Is there something wrong with it or did i make a mistake or something?
Hope to hear from you guys soon!

J.Molenaar. :slight_smile:

Remove the broken secondary param you are using for triggering the event and you should be fine.

Thanks for the reply!

What do you exactly mean with the bad events?

Greetings, Jeff.

You are sending MessagePart[“weapon”], but you never define what the string equals in the array.
Also, why do you stringsplit if you don’t have any secondary if’s?

Can you send me a preview anout what u mean?
Scripting lua is kinda new to me haha :smiley:

AddEventHandler('chatMessage', function(source, n, msg)
	local Message = string.lower(msg)

	if Message == "/weapon" then
		TriggerClientEvent('Rpg', source)
		TriggerClientEvent('Ak', source)
		TriggerClientEvent('Sniper', source)
		CancelEvent()
	end
end)

well i gues you are the one that doesnt understand me and my script haha.
i wanted to make a " /weapon " script.

Do you English? Do you read? It currently is a copy paste of your script, just not using any stringsplitter as you don’t need it anyways.
If you want “/weapon AK” you’d have to do args[1] == "/weapon" and args[2] == "AK".
Adding a broken array to your params won’t do anything but, break it.

Woahh sorry i saw i made a typing mistake, i mrnt that i wanted a /weapon “id” script. Indeed like your’e last message.
Im really sorry if i offended you!

Have a awesome day,
~ j.molenaar ~

If you want an “id” script, you’ll have to define that with different if statements like I said.
The param “MessagePart["weapon"]” is not how you do it.

Well thanks man, you helped me out alot!
Im going to rescript it when im home today.
#workingdayz :smiley:

Have a great day!

Well okay still struggling with the code.

AddEventHandler("chatMessage", function(source, n, message)
	local cm = stringsplit(message, " ")
	
	if cm[1] == "/weapon" then
		if cm[2] == "ak" then
			CancelEvent()
			TriggerClientEvent("Ak", source)
		elseif cm[2] == "rpg" then
			CancelEvent()
			TriggerClientEvent("Rpg", source)
		elseif cm[2] == "sniper" then
			CancelEvent()
			TriggerClientEvent("Sniper", source)
		elseif cm[2] == "" then
			CancelEvent()
			TriggerClientEvent("chatMessage", source, "^1WEAPON COMMANDS:^2 /weapon ak, /weapon sniper, /weapon rpg")
		end
	end
end)

function stringsplit(inputstr, sep)
    if sep == nil then
        sep = "%s"
    end
    local t={} ; i=1
    for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
        t[i] = str
        i = i + 1
    end
    return t
end

thats what i got now, and still isnt working.
if i press t and type in /weapon ak nothing appears.

Should be cm[0] == “/weapon”
and cm[1] == “ak”

still doesnt work either.
i really dont know why.

	elseif cm[2] == "" then

elseif cm[1] == nil then
" " <-- is still a string, which means it contains data.

Hmm gonna give that a try when im at home, thanks for the reply both of u!
I really appreciate it.

Have a great day!

Well that doesnt work either,

this is my script as i have it now.

Client:

RegisterNetEvent("rpg")
AddEventHandler("rpg", function(number) --I also added the argument here
	GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("weapon_rpg"), 10, true)
	
end)

RegisterNetEvent("ak")
AddEventHandler("ak", function(number) --I also added the argument here
	GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("weapon_assaultrifle"), 1000, true)
	
end)

RegisterNetEvent("sniper")
AddEventHandler("sniper", function(number) --I also added the argument here
	GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("weapon_heavysniper"), 100, true)
	
end)

Server:

AddEventHandler("chatMessage", function(source, n, message)
	local cm = stringsplit(message, " ")
	
	if cm[0] == "/weapon" then
		if cm[1] == "ak" then
			TriggerClientEvent("ak", source)
		elseif cm[1] == "rpg" then
			TriggerClientEvent("rpg", source)
		elseif cm[1] == "sniper" then
			TriggerClientEvent("sniper", source)
		elseif cm[1] == nil then
			TriggerClientEvent("chatMessage", source, "^1WEAPON COMMANDS:^2 /weapon ak, /weapon sniper, /weapon rpg")
		end
	end
end)

function stringsplit(inputstr, sep)
    if sep == nil then
        sep = "%s"
    end
    local t={} ; i=1
    for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
        t[i] = str
        i = i + 1
    end
    return t
end

Hope that you guys soon will help me out.

Somebody that does know a answer?