Value from Fireserver returns as nil

I have a script that sets a player’s weapon.

Localscript, set inside of a textbutton

local plr = game.Players.LocalPlayer
local Request = game.ReplicatedStorage:FindFirstChild("changeweapon")
local Players = game:GetService("Players")

script.Parent.MouseButton1Click:Connect(function(plr,weapon,id)
	local weapon = 1
	local id = 01

	Request:FireServer(plr, weapon, id)
end)

The request is fired, and the receiving script can pick it up and it will set the weapon value… but it sets it to Nil, disregarding the weapon value sent to it.

Regular script, Set inside ServerScriptService, reading a RemoteEvent from ReplicatedStorage

local Request = game.ReplicatedStorage:FindFirstChild("changeweapon")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local function onrequestFired(plr, weapon, wepid)
	warn(plr.Name)

	local folder = game.ServerStorage.Statfile:FindFirstChild(plr.Name).statnumbers
	
	folder.Weaponid0.Value = weapon
	warn(weapon)
end
Request.OnServerEvent:Connect(onrequestFired)

warn(weapon) returns as nil
How would i go about actually sending the weapon value? Which scripts would i have to change to correct this error?

In the first line here, get rid of everything between the parentheses. In the second to last line, get rid of plr. The first issue is that MouseButton1Click doesn’t give any function arguments and so your variables are being set to nil. The second issue is that FireServer automatically sends the player as the first argument. Leave the server the same.

What should i replace MouseButton1Click with? So far i cant find any suitable replacements other than MouseButton1Down

No no what he means is remove plr,weapon,id from the script.Parent.MouseButton1Click:Connect(function(plr,weapon,id) and also remove the plr out of the Request:FireServer(plr, weapon, id) since the server’s OnServerEvent, first argument is always the player

2 Likes