I have been struggling really hard to limit the script from spawning a certain amount of objects for each player.
I have created a script that allows to spawn objects from a GUI via local script > remote event
but I want to give each player a limit of 5 objects
What do you want to achieve? Limit the player from spamming objects
What solutions have you tried so far? I looked far and wide, I have tried for i,v ipairs, pairs(t), now if and elseif statements. math.clamps,
attribute for limit and attribute for how many spawned (latter not updating when the player spawns an object))
trying for loops either doesn’t give the expected result or pauses rendering and gives me an error
attempt to get length of a instance value
for now this is the current code sample with the method i am trying
local function giveCarrierStat(Players)
Players:SetAttribute("isCarrying", false)
Players:SetAttribute("cargoLimit", 5)
local cargoLimit = Players:GetAttribute("cargoLimit", 5)
local playerCargoFolder = Instance.new("Folder", cargoStorage)
playerCargoFolder.Name = Players.Name
local cargAmount = playerCargoFolder:GetChildren()
local playerGui = Players:WaitForChild("PlayerGui")
if #cargAmount < cargoLimit then
local function instantiateCrate(Players, parent, partPosition, value, destination, spawner)
local newCargo = newCrate:Clone()
newCargo.Parent = cargoStorage:FindFirstChild(Players.Name)
newCargo.Position = partPosition
newCargo:SetAttribute("Value", value)
newCargo:SetAttribute("Destination", destination)
newCargo:SetAttribute("Spawner", spawner)
end
insC.OnServerEvent:Connect(instantiateCrate)
elseif #cargAmount > cargoLimit then
local Warn = playerGui:FindFirstChild("WarnLimit")
Warn.Enabled = true
wait(3)
Warn.Enabled = false
end
end
Players.PlayerAdded:Connect(giveCarrierStat)
thank you everyone inadvance