I’m trying to drop boxes that give you rewards.
Stack overflow crashing my game.
I dont know where to start fixing it.
Script
local Debris = game:GetService(“Debris”)
local Players = game:GetService(“Players”)
local TweenService = game:GetService(“TweenService”)
local Baseplate = workspace.Baseplate
local DropTemplate = game:GetService(“ServerStorage”).NormalDrop
local Generator = Random.new()
local Drops = {}
Drops.__index = Drops
function Drops:GetPosition(LowestPos, HighestPos)
local X = Generator:NextNumber(LowestPos.X, HighestPos.X)
local Z = Generator:NextNumber(LowestPos.Z, HighestPos.Z)
local Position = Vector3.new(X, 5, Z)
return self:GetPosition(LowestPos, HighestPos)
end
function Drops:SetPosition(LowestPos, HighestPos)
local Drop = self.Drop
Drop.Position = self:GetPosition(LowestPos, HighestPos)
self:SetPosition(LowestPos, HighestPos)
end
function Drops:SetProperties()
local Drop = self.Drop
local RewardLabel = Drop.Display.RewardLabel
RewardLabel.Text = self.Reward
Drop.Parent = workspace.Drops
self:SetPosition((Baseplate.Position - Baseplate.Size / 2), (Baseplate.Position + Baseplate.Size / 2))
TweenService:Create(Drop, TweenInfo.new(0, Enum.EasingStyle.Back, Enum.EasingDirection.Out, 0, true), {Position = Drop.Position + Vector3.new(2, 2, 2)}):Play()
TweenService:Create(Drop, TweenInfo.new(0, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0), {Orientation = Vector3.new(0, 360, 0)}):Play()
delay(120, function()
if not Drop then
return
end
Debris:AddItem(Drop, 8)
for Blink = 1, 8 do
wait(1)
end
end)
end
function Drops.New()
local DropObject = setmetatable({}, Drops)
DropObject.Reward = Generator:NextInteger(200, 1550)
DropObject.Drop = DropTemplate:Clone()
local Connection
local Drop = DropObject.Drop
Connection = Drop.Touched:Connect(function(Hit)
local Character = Hit.Parent
local player = Character:FindFirstChildOfClass("Humanoid") and Players:GetPlayerFromCharacter(Character)
if player then
Connection:Disconnect()
player.leaderstats["Time Alive"].Value += DropObject.Reward
local Dissappear = TweenService:Create(Drop, TweenInfo.new(0.5), {Transparency = 1})
Dissappear:Play()
Dissappear.Completed:Wait()
Drop:Destroy()
end
end)
return DropObject
end
return Drops