Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Created By Soovier And Striker2783
- local ItemsInGame = 0
- local Duration = 5
- local MaxItems = 8
- --Basic Variables
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local MoneyItems = ReplicatedStorage.MoneyItems
- local TrinketLocations = game.Workspace.TrinketLocations
- local RS = game:GetService("ReplicatedStorage")
- --Debounce for spawning
- local Debs = false
- local MoneyItems = RS.MoneyItems
- --Table for the chance of spawning a trinket
- local TrinketTable = {
- [MoneyItems.Scroll] = 5; --5%
- [MoneyItems.Diamond] = 10; --10%
- [MoneyItems.Opal] = 35; --35%
- [MoneyItems.Goblet] = 50; --50%
- };
- --Total Weights
- local TrinketTotal = 0
- --Finding the total weights.
- for i,v in pairs(TrinketTable) do
- TrinketTotal = TrinketTotal + v
- end
- --Positions to spawn
- local AvailiblePos = {}
- --Makes the table above with the positions
- for i,v in pairs(TrinketLocations:GetChildren()) do
- AvailiblePos[#AvailiblePos + 1] = v
- end
- --Picks a random Trinket based on the weights
- local function SpinTrinket()
- local rand = math.random() * TrinketTotal
- local Add = 0
- for i, v in pairs(TrinketTable) do
- if rand > Add and rand <= v + Add then
- return i
- else
- Add = Add + v
- end
- end
- return SpinTrinket()
- end
- --Creates the Trinket
- function CreateNewItem()
- if ItemsInGame >= 8 or Debs then return end --Checks the amount of items and if it can spawn or not
- Debs = true
- local NewItem = SpinTrinket():Clone() --Clones a randomly picked Trinket
- local Pick = math.random(1,#AvailiblePos) --Gets the Index of the table in AvailiblePos
- local Pos = AvailiblePos[Pick] --Gets the Part that has the position
- table.remove(AvailiblePos, Pick) --Removes the Part that has the position from the AvailiblePos list
- local TrinketRay = workspace:Raycast(Pos.Position, Vector3.new(0,-180,0) * 30) --Puts a Trinket on the higher block
- if not TrinketRay then return end --Checks if it intersects anything
- NewItem.Position = TrinketRay.Position --Places the Trinket
- NewItem.Parent = workspace --Parents the Trinket
- ItemsInGame += 1 --Adds the amount of in game items
- NewItem.ClickDetector.MouseClick:Connect(function(plr) --Event that checks if the Trinket is clicked
- ItemsInGame -= 1 --Removes 1 from game items
- AvailiblePos[#AvailiblePos + 1] = Pos --Re adds the position to AvailiblePos
- NewItem:Destroy() --Destroys the Trinket
- plr.Silver.Value = plr.Silver.Value + 5 --Adds 5 silver to the player
- wait(Duration) --Waits Duration
- if ItemsInGame < MaxItems then --Checks to make sure there's enough items
- for i = 1, MaxItems - ItemsInGame do --Repeats the amount of times the items in game are off by max times
- if not CreateNewItem() then --Checks whether the creation of the trinket was successful
- wait(Duration) --Waits Duration
- end
- end
- end
- end)
- wait(Duration) --Waits Duration
- Debs = false
- return true
- end
- while ItemsInGame < MaxItems do --Just for the start to get the max items
- CreateNewItem() --Creates New Trinkets
- wait() --Waits to not break the script.
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement