So, here is my script for spawning a Dummies. I want to limit a number of Dummies to one for each player, how would I do that?
This script is placed in the ServerScriptService:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local spawnEvent = ReplicatedStorage:WaitForChild("SpawnEvent")
local dummy = ReplicatedStorage:WaitForChild("Dummy")
function SpawnDummy(player)
local dummyClone = dummy:Clone()
dummyClone.Parent = game.Workspace
dummyClone.Name = player.Name.."'s "..dummy.Name
dummyClone.Owner.Value = player.Name
end
spawnEvent.OnServerEvent:Connect(SpawnDummy)
You could attach a bool value to the player and set it as true when they spawn a dummy, after that you could use something similar to a debounce and not allow a player to spawn a dummy if the value is true.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local spawnEvent = ReplicatedStorage:WaitForChild("SpawnEvent")
local dummy = ReplicatedStorage:WaitForChild("Dummy")
local playerDummiesSpawned = {}
function SpawnDummy(player)
if table.find(playerDummiesSpawned,player) then return end
table.insert(playerDummiesSpawned,player)
local dummyClone = dummy:Clone()
dummyClone.Parent = game.Workspace
dummyClone.Name = player.Name.."'s "..dummy.Name
dummyClone.Owner.Value = player.Name
end
spawnEvent.OnServerEvent:Connect(SpawnDummy)
It would still restrict spawning if the player leaves and rejoin. I’m not sure what your purpose is but this is a way to do it.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local spawnEvent = ReplicatedStorage:WaitForChild("SpawnEvent")
local dummy = ReplicatedStorage:WaitForChild("Dummy")
local ifCloned = false
function SpawnDummy(player)
if ifCloned then
return
end
local dummyClone = dummy:Clone()
dummyClone.Parent = game.Workspace
dummyClone.Name = player.Name.."'s "..dummy.Name
dummyClone.Owner.Value = player.Name
ifCloned = true
end
spawnEvent.OnServerEvent:Connect(SpawnDummy)
Just add a Boolean variable which represents if a clone has been made or not.
Yeah, you can turn it into a debounce if you wish, like so:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local spawnEvent = ReplicatedStorage:WaitForChild("SpawnEvent")
local dummy = ReplicatedStorage:WaitForChild("Dummy")
local ifCloned = false
function SpawnDummy(player)
if ifCloned then
return
end
ifCloned = true
local dummyClone = dummy:Clone()
dummyClone.Parent = game.Workspace
dummyClone.Name = player.Name.."'s "..dummy.Name
dummyClone.Owner.Value = player.Name
task.wait(5) --cooldown
ifCloned = false
end
spawnEvent.OnServerEvent:Connect(SpawnDummy)
I just noticed “if ifCloned” looks weird, feel free to change it from that.