#Spawn different Drops
8 messages · Page 1 of 1 (latest)
--// Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")
--// Variables
local Modules = ReplicatedStorage.Modules
local GameSettings = ReplicatedStorage["Game Settings"]
if GameSettings.GameType.Value ~= "Collector" then return end
local DropsFolder = ServerStorage.Drops
local Drops = DropsFolder:GetChildren()
local DropTemplates = {}
for _, drop in pairs(Drops) do
table.insert(DropTemplates, drop)
end
local Multipliers = require(Modules.Multipliers)
local DropRewards = {
[DropTemplates[1].Name] = 1, -- Drop1
[DropTemplates[2].Name] = 50, -- Drop2
[DropTemplates[3].Name] = 100, -- Drop3
}
function SpawnObject(v)
if #v:GetChildren() < GameSettings.MaxDrops.Value then
local randomDrop = DropTemplates[math.random(#DropTemplates)]
local NewDrop = randomDrop:Clone()
local X, Y, Z = math.random(v.Size.X) - v.Size.X/2 + v.Position.X, v.Position.Y + 5, math.random(v.Size.Z) - v.Size.Z/2 + v.Position.Z
local RandomPosition = Vector3.new(X, Y, Z)
NewDrop.Position = RandomPosition
NewDrop.Parent = v
local Hit = false
NewDrop.Touched:Connect(function(HitPart)
if Hit then return end
if HitPart.Parent:FindFirstChild("Humanoid") then
Hit = true
local Character = HitPart.Parent
local Player = Players:GetPlayerFromCharacter(Character)
local reward = DropRewards[NewDrop.Name]
Player.Data.PlayerData.Currency.Value += reward * Multipliers.CurrencyMultiplier(Player)
NewDrop:Destroy()
end
end)
NewDrop.CanCollide = true
task.wait(2.5)
pcall(function()
NewDrop.Anchored = false
NewDrop.CanCollide = false
end)
end
end
while task.wait(1) do
for _, Area in workspace.Map.CollectAreas:GetChildren() do
coroutine.wrap(function()
SpawnObject(Area)
end)()
end
end
this is because model doesn't have a property called position so you just have to set the primarypart and use it in this script as it will act parent of the model
can i make a object and do in the objects the parts?
wdym?
you set a primarypart inside of the model. i mean like any part and you just set it to primarypart use it position example: model.PrimaryPart.Position
because i made a Coin stack with more than one coin and i must group thme together