#Spawn different Drops

8 messages · Page 1 of 1 (latest)

waxen trench
#

Hello I scriptet this Script (look in the Post Too long to post alone)

The Script is not working the Error is: ServerScriptService.SpawnHandler:66: Position is not a valid member of Model "Drop3"

I want to make that one of these Models get Choosen and get Spawned in the Area. You should get differnent Rewards.

#

--// 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
worthy hull
waxen trench
#

can i make a object and do in the objects the parts?

worthy hull
#

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

waxen trench
#

because i made a Coin stack with more than one coin and i must group thme together