Sending multiple variables through a remote event being problematic

I’m trying to make the purchasing of guns work, but when I try to pass multiple variables through a remote event it tells me that the other variables are the first variable.

The error without tostring:

ServerScriptService.GunPurchased:4: invalid argument #3 (string expected, got Instance)  -  Server - GunPurchased:4
Stack Begin  -  Studio
Script 'ServerScriptService.GunPurchased', Line 4  -  Studio - GunPurchased:4
Stack End  -  Studio

With tostring()

tostring is not a valid member of Player "Players.IdontPlayz343"  -  Server - GunPurchased:4
Stack Begin  -  Studio
Script 'ServerScriptService.GunPurchased', Line 4  -  Studio - GunPurchased:4
Stack End  -  Studio

Client Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GunPurchased = ReplicatedStorage:WaitForChild("GunPurchased")
local player = game.Players.LocalPlayer
local LaserRifle = script.Parent
local selected = player.PlayerGui.Lobby.Weapons.InfoFrame.Selected
local selectedInfo = player.PlayerGui.Lobby.Weapons.InfoFrame.SelectedInfo
LaserRifle.MouseEnter:Connect(function()
	selected.Text = "Laser Rifle"
	selectedInfo.Text = "Range: 100 studs | Firerate: 4 shots-per-second | Secondary Fire: Grenade Launcher | Grenade Tag Radius: 10 studs from the point of detonation."
end)
LaserRifle.MouseButton1Down:Connect(function()
	if player.leaderstats.Lazercards.Value == 200 or player.leaderstats.Lazercards.Value >= 200 then
		local Gun = "LaserRifle"
		local GunPrice = 200
		GunPurchased:FireServer(player, Gun, GunPrice)
	end
end)

Server Script

local GunBought = game:GetService("ReplicatedStorage"):WaitForChild("GunPurchased")
GunBought.OnServerEvent:Connect(function(player, Gun, GunPrice)
	local GunPurchased = Instance.new("BoolValue")
	GunPurchased.Name = Gun
	GunPurchased.Parent = player:WaitForChild("OwnedGuns")
	player.leaderstats.Lazercards.Value -= GunPrice
end)

Please feel free to ask if more info is needed

1 Like

player is already sent by default from a client, remove that part from your LocalScript.

2 Likes

why do i have to say this
The player is automatically passed when firing a remote event, so your arguments end up looking like

gun = player
GunPrice = gun
1 Like

Client Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GunPurchased = ReplicatedStorage:WaitForChild("GunPurchased")
local player = game.Players.LocalPlayer
local LaserRifle = script.Parent
local selected = player.PlayerGui.Lobby.Weapons.InfoFrame.Selected
local selectedInfo = player.PlayerGui.Lobby.Weapons.InfoFrame.SelectedInfo
LaserRifle.MouseEnter:Connect(function()
	selected.Text = "Laser Rifle"
	selectedInfo.Text = "Range: 100 studs | Firerate: 4 shots-per-second | Secondary Fire: Grenade Launcher | Grenade Tag Radius: 10 studs from the point of detonation."
end)
LaserRifle.MouseButton1Down:Connect(function()
	if player.leaderstats.Lazercards.Value == 200 or player.leaderstats.Lazercards.Value >= 200 then
		local Gun = "LaserRifle"
		local GunPrice = 200
		GunPurchased:FireServer(Gun, GunPrice)
	end
end)

Server Script

local GunBought = game:GetService("ReplicatedStorage"):WaitForChild("GunPurchased")
GunBought.OnServerEvent:Connect(function(player, Gun, GunPrice)
	local GunPurchased = Instance.new("BoolValue")
	GunPurchased.Name = Gun
	GunPurchased.Parent = player:WaitForChild("OwnedGuns")
	player.leaderstats.Lazercards.Value -= GunPrice
end)

here

2 Likes

nice to see you found your solutions

1 Like

Thank you guys, I didn’t know roblox automatically passed the player from client to server.

1 Like