There’s an ice cube that is scripted to give things around it an ice cover and I need these covers to sort of stay on the parts and not pass anywhere past them or else it starts to look like the images below
code:
local frozedparts = {}
local FreezeParts = {}
local module = require(game.ReplicatedStorage.lotsoffunstuff)
local ice = script.Ice:Clone()
local playersfrozen = {}
script.Ice:Destroy()
local function func(v, vec)
if vec and v then
local newpart = Instance.new("Part", workspace)
newpart.Color = script.Parent.Color
newpart.Name = "FreezePart"
local playersfrozen = {}
for i,v in pairs(script.icedecals:GetChildren()) do
local clon = v:Clone()
clon.Parent = newpart
end
newpart.Color = Color3.fromRGB(4, 175, 236)
newpart.Material = Enum.Material.SmoothPlastic
newpart.CanCollide = false
newpart.Transparency = 0.7
newpart.Touched:Connect(function(hit)
local hum = module.FindHumanoid(hit.Parent)
if hum then
local root = hum.Parent:FindFirstChild("HumanoidRootPart")
if root then
if playersfrozen[hum.Parent] == nil then
playersfrozen[hum.Parent] = true
root.Anchored = true
local icing = ice:Clone()
table.insert(FreezeParts, icing)
icing.Parent = workspace
icing.CFrame = root.CFrame * CFrame.Angles(math.rad(-90),0,0)
wait(2)
root.Anchored = false
icing:Destroy()
playersfrozen[hum.Parent] = nil
end
end
end
end)
local ray = RaycastParams.new()
ray.IgnoreWater = true
ray.FilterType = Enum.RaycastFilterType.Exclude
ray.FilterDescendantsInstances = {script.Parent, FreezeParts, frozedparts}
local realray = workspace:Raycast(script.Parent.Position, vec * 50, ray)
if realray then
local partthing = realray.Instance
if partthing then
local hum = module.FindHumanoid(partthing.Parent)
if not hum then
--if partthing.Locked == false then
table.insert(frozedparts, partthing)
newpart.CFrame = CFrame.new(realray.Position, realray.Position + realray.Normal)
if (script.Parent.Position - newpart.Position).Magnitude <= 25 then
table.insert(FreezeParts,newpart)
newpart.Orientation = partthing.Orientation
local SizeX = math.clamp(newpart.Size.X, partthing.Size.X - partthing.Size.X/2, partthing.Size.X + partthing.Size.X/2)
local SizeZ = math.clamp(newpart.Size.Z, partthing.Size.Z - partthing.Size.Z/2, partthing.Size.Z + partthing.Size.Z/2)
local SizeY = math.clamp(newpart.Size.Y, partthing.Size.Y - partthing.Size.Y/2, partthing.Size.Y + partthing.Size.Y/2)
local fitvector = Vector3.new(SizeX, SizeY, SizeZ)
if partthing.Size.X <= 50 or partthing.Size.Z <= 50 or partthing.Size.Y <= 50 then
if partthing.Size.X > 20 or partthing.Size.Y > 20 or partthing.Size.Z > 20 then
newpart.Size = fitvector -- * Vector3.new(0.8,0.8,0.8)
else
newpart.Size = fitvector
end
else
newpart:Destroy()
end
else
newpart:Destroy()
end
-- end
else
local rootpart = hum.Parent:FindFirstChild("HumanoidRootPart")
if rootpart then
spawn(function()
local icing = ice:Clone()
table.insert(FreezeParts, icing)
icing.Parent = workspace
icing.CFrame = rootpart.CFrame * CFrame.Angles(math.rad(-90),0,0)
rootpart.Anchored = true
wait(2)
rootpart.Anchored = false
icing:Destroy()
end)
end
end
end
end
newpart.Anchored = true
end
end
wait(9)
script.Parent.ice_shatter:Play()
for i,v in pairs(workspace:GetDescendants()) do
if v ~= script.Parent then
if v:IsA("Part") then
local magnitude = (script.Parent.Position - v.Position).Magnitude
if magnitude <= 50 then
func(v, script.Parent.CFrame.RightVector.Unit)
func(v, -script.Parent.CFrame.RightVector.Unit)
func(v, script.Parent.CFrame.UpVector.Unit)
func(v, -script.Parent.CFrame.UpVector.Unit)
func(v, script.Parent.CFrame.LookVector.Unit)
func(v, -script.Parent.CFrame.LookVector.Unit)
end
end
end
end