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