How would I change this to just spawn the part anywhere without checking inside part and make it so It can’t spawn inside region.
I tried removing inside part but then the whole thing breaks.
SCRIPT HERE
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 function IsInsidePart(Position, Part)
local ObjectPosition = (Part.CFrame - Vector3.new(0, 16.774, 0)):PointToObjectSpace(Position)
local XInside = math.abs(ObjectPosition.X) <= (Part.Size.X + 40) / 2
local YInside = math.abs(ObjectPosition.Y) <= Part.Size.Y / 2
local ZInside = math.abs(ObjectPosition.Z) <= (Part.Size.Z + 40) / 2
return XInside and YInside and ZInside
end
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 not IsInsidePart(Position, workspace.Region) and Position or self:GetPosition(LowestPos, HighestPos)
end
function Drops:SetPosition(LowestPos, HighestPos)
local Drop = self.Drop
Drop.Position = self:GetPosition(LowestPos, HighestPos)
if #Drop:GetTouchingParts() > 0 then
self:SetPosition(LowestPos, HighestPos)
end
end
function Drops:SetProperties()
local Drop = self.Drop
local RewardLabel = Drop.Display.RewardLabel
local Offset = Vector3.new(#Players:GetPlayers() * 6, 0, #Players:GetPlayers() * 6)
RewardLabel.Text = self.Reward
Drop.Parent = workspace.Drops
self:SetPosition((Baseplate.Position - Baseplate.Size / 2) + Offset, (Baseplate.Position + Baseplate.Size / 2) - Offset)
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)
local cache = require(game.ServerScriptService.ProfileCacher)
local profile
profile = cache[player]
if profile == nil then
repeat
wait()
profile = cache[player]
until profile ~= nil
end
function UpdateLeaderstats(player, data)
if player and data then
local leaderstats = player:FindFirstChild('leaderstats')
if leaderstats then
for i,v in pairs(leaderstats:GetDescendants()) do
if data[v.Name] then
v.Value = data[v.Name]
end
end
end
end
end
if player then
Connection:Disconnect()
profile.Data["Time Alive"] += DropObject.Reward
UpdateLeaderstats(player, profile.Data)
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