Hello, I’m using this function to float and spin the money parts in my game, as well as tween text when you walk in and out of the range. This function works, but it only connects to one of them for some reason, and I don’t know why
Edit: It might be StreamingEnabled making the other one not available (right now I only have two), I’m not sure, because it’s not THAT far away from it… If it is, how do I make sure that all of the CashParts are in the table?
Here’s that part of the script:
----------- MONEY HANDLER (Visuals) -----------
do
local CashParts = workspace.MoneySpawns:GetChildren()
--print("Got cash parts.")
function FloatAndSpin(part)
local RunService = game:GetService("RunService")
local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local renderdistance = 400
local counter = 0
local threshold = 1.5
local inc = 2.5
local Angle = math.deg(0.05)
local plrchar = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local up = false
RunService.RenderStepped:Connect(function(dt)
if part.Parent and part.Transparency < 1 then --and (plrchar.HumanoidRootPart.Position - part.Position).magnitude < renderdistance then -- Check if the part exists
part.CFrame = part.CFrame * CFrame.Angles(Angle * dt, 0, 0)
if not up then
--print("going up")
--print(counter)
counter = counter + (inc * dt)
part.CFrame = part.CFrame * CFrame.new(inc * dt, 0, 0)
if counter >= threshold then
up = true
end
else
--print("going down")
counter = counter - (inc * dt)
--print(counter)
part.CFrame = part.CFrame * CFrame.new(-(inc * dt), 0, 0)
if counter <= 0 then
up = false
end
end
end
end)
end
function TweenText(part)
local plrchar = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local guidistance = 20
local tweened = false
local enabled = true
game:GetService("RunService").Heartbeat:Connect(function()
if (plrchar.HumanoidRootPart.Position - part.Position).magnitude < guidistance and part.Transparency < 1 then
--print((plrchar.HumanoidRootPart.Position - part.Position).magnitude)
if not tweened then
part.BillboardGui.Frame:TweenSize(UDim2.new(1,0,1,0), Enum.EasingDirection.Out, Enum.EasingStyle.Back, .65, true, function()
--print("tweened up")
tweened = true
end)
end
elseif (plrchar.HumanoidRootPart.Position - part.Position).magnitude > guidistance and part.Transparency < 1 then
--print((plrchar.HumanoidRootPart.Position - part.Position).magnitude)
if tweened then
part.BillboardGui.Frame:TweenSize(UDim2.new(0,0,0,0), Enum.EasingDirection.In, Enum.EasingStyle.Back, .35, true, function()
--print("tweened down")
tweened = false
end)
end
end
end)
end
for i, cashpart in pairs(CashParts) do
FloatAndSpin(cashpart)
TweenText(cashpart)
print("Connected cashpart")
end
wait(3) -- wait for GC?
end