If its a LocalScript, use a Server Script
if a Server Script, should work for every player
If its inside ServerScriptService, just put the Monster Inside the script
while task.wait(MDT) do
CD = true
local RM = math.random(1,10)
if RM == 1 then
CD = false
local Mob = script.Monster:Clone()
Mob.Parent = workspace
Mob:SetPrimaryPartCFrame(Spawn1.CFrame + Vector3.new(0,2,0))
elseif RM == 2 then
CD = false
local Mob = script.Monster:Clone()
Mob.Parent = workspace
Mob:SetPrimaryPartCFrame(Spawn2.CFrame + Vector3.new(0,2,0))
elseif RM == 3 then
CD = false
local Mob = script.Monster:Clone()
Mob.Parent = workspace
Mob:SetPrimaryPartCFrame(Spawn3.CFrame + Vector3.new(0,2,0))
elseif RM == 4 then
CD = false
local Mob = script.Monster:Clone()
Mob.Parent = workspace
Mob:SetPrimaryPartCFrame(Spawn4.CFrame + Vector3.new(0,2,0))
end
end
You cant, You can only use Stepped and Heartbeat on the Server
@alexjouq This does the same same thing, there is not really a point in doing it
I would recommend just numbering the Monsters to randomize which Monster will be cloned
First, here’s the code in text form using OCR, but you should really post your code in the thread:
cd = false
local Spawn1 = game.Workspace["Roomate/CheackMateSpawnPoints"].UpperSpawnPoint
local Spawn2 = game.Workspace["Roomate/CheackMateSpawnPoints"].LowerSpawnPoint
local Spawn3 = game.Workspace["Roomate/CheackMateSpawnPoints"].RightSpawnPoint
local Spawn4 = game.Workspace["Roomate/CheackMateSpawnPoints"].LeftSpawnPoint
local MDT = 5
game["Run Service"].RenderStepped:Connect(
function()
if cd == false then
cd = true
local RandomNumber = math.random(1, 10)
if RandomNumber == 10 then
local RandomNumber2 = math.random(1, 4)
if RandomNumber2 == 1 then
local Monster = game.ServerStorage.Monsters.Roomate
local MonsterClone = Monster:Clone()
MonsterClone.Parent = game.Workspace
MonsterClone.HumanoidRootPart.CFrame = Spawnl.CFrame
wait(MDT)
cd = false
end
if RandomNumber2 == 2 then
local Monster = game.ServerStorage.Monsters.Roomate
local MonsterClone = Monster:Clone()
MonsterClone.Parent = game.Workspace
MonsterClone.HumanoidRootPart.CFrame = Spawn2.CFrame
wait(MDT)
cd = false
end
if RandomNumber2 == 3 then
local Monster = game.ServerStorage.Monsters.Roomate
local MonsterClone = Monster:Clone()
MonsterClone.Parent = game.Workspace
MonsterClone.HumanoidRootPart.CFrame = Spawn2.CFrame
wait(MDT)
cd = false
end
if RandomNumber2 == 4 then
local Monster = game.ServerStorage.Monsters.Roomate
local MonsterClone = Monster:Clone()
MonsterClone.Parent = game.Workspace
MonsterClone.HumanoidRootPart.CFrame = Spawn4.CFrame
wait(MDT)
cd = false
end
end
end
end
)
Second, here’s the code but vastly less redundant:
local spawnPointContainer = workspace:FindFirstChild("Roomate/CheackMateSpawnPoints")
local spawnPoints = {}
for _, dir in {"Upper", "Lower", "Right", "Left"} do
table.insert(spawnPoints, spawnPointContainer:FindFirstChild(dir .. "SpawnPoint"))
end
local MDT = 5
while true do
task.wait(1)
local RandomNumber = math.random(1, 10)
if RandomNumber == 10 then
local Monster = game.ServerStorage.Monsters.Roomate
local MonsterClone = Monster:Clone()
MonsterClone.Parent = workspace
local SpawnCFrame = spawnPoints[math.random(1, #spawnPoints)].CFrame
MonsterClone.HumanoidRootPart.CFrame = SpawnCFrame
task.wait(MDT)
end
end
Finally, post errors that you see from the Output console in this thread.
Whereas before, he would’ve had to copy paste another set of code blocks. I know OP is new to programming, so I figured I’d show a side by side of copy pasted code and efficient code.
Each monster has its own script. Some have a chance to spawn every second, Some will spawn every Minute. Some will spawn once every day passes in my game