Hello! Im trying to make a sandbox style game (Like miners haven) and Im trying to subtract 1 from the number of items in a players inventory! The following script runs when the player places an item. However it always has the error ServerScriptService.ServerPlacement:10: bad argument #2 to '?' (string expected, got Object)
What can I do to fix this? (The value im calling at the end is an IntValue)
local items = game:GetService("ReplicatedStorage").Items game:GetService("ReplicatedStorage").ClientPlaced.OnServerEvent:Connect(function(player, itemName, location) local itemTemplate = items:FindFirstChild(itemName) if (itemTemplate) then local item = itemTemplate:clone() item.Parent = workspace.Base.ItemHolder item:SetPrimaryPartCFrame(location[1]) game.Players[player].PlayerGui.PlayerScreen.Inventory.ImageButton.TextLabel[itemName].value = game.Players[player].PlayerGui.PlayerScreen.Inventory.ImageButton.TextLabel[itemName].value - 1 end end)
Also i tried it by doing it on the players end, however it subtracted 1 40-50 times!
Line 10. Event OnServerEvent
, returns Object Player
from the first argument. But since indexing children with special names with [
and ]
uses strings instead of objects. It's best if you use [player.Name]
instead of [player]
because player
is an object and player.Name
is a string.