Function Problem

local tool = script.Parent
local fireEvent = tool:FindFirstChild(“fire”)

local deleteTime = 15

function spawnPart(pos, amount)
for i = 0,amount do
local partColor = BrickColor.random()
local part = Instance.new(“Part”)
part.Transparency = 1
part.Parent = workspace.parts
part.CFrame = pos
part.BrickColor = partColor
return part
end
end

fireEvent.OnServerEvent:Connect(function(player, pos)
local spawned = player.leaderstats.spawned
spawnPart(pos,2)
local part = spawnPart(pos,2)

spawned.Value = spawned.Value + 1
part.Transparency = 1
for i = 1, 10 do
wait(0.1)
part.Transparency = part.Transparency - 0.1
end

task.wait(deleteTime)

for i = 1, 10 do
wait(0.1)
part.Transparency = part.Transparency + 0.1
end

part:Destroy()
end)

The second part spawned is invisible. Why?

1 Like

It’s seems you using loops to set a parts transparency. Try using Tweens also you only 1 return 1 part from the Spawn Part function. This might be what it looks like:

local tool = script.Parent
local fireEvent = tool:FindFirstChild("fire")

local deleteTime = 15
local TweenService = game:GetService("TweenService")

function spawnPart(pos, amount)

    local Parts = {}

    for i = 0, amount do
        local partColor = BrickColor.random()
        local part = Instance.new("Part")
        part.Transparency = 1
        part.Parent = workspace.parts
        part.CFrame = pos
        part.BrickColor = partColor
        table.insert(Parts,part)
    end

  return Parts

end

fireEvent.OnServerEvent:Connect(function(player, pos)
    local spawned = player.leaderstats.spawned
    spawnPart(pos, 2)
    local parts = spawnPart(pos, 2)

    spawned.Value = spawned.Value + 1
    parts[1].Transparency = 1

    local transparencyGoal = 0
    local transparencyInfo = TweenInfo.new(1, Enum.EasingStyle.Linear)

    local transparencyTween = TweenService:Create(parts[1], transparencyInfo, { Transparency = transparencyGoal })
    transparencyTween:Play()

    transparencyTween.Completed:Wait() -- Wait for the tween to complete

    task.wait(deleteTime)

    transparencyGoal = 1
    transparencyTween = TweenService:Create(parts[2], transparencyInfo, { Transparency = transparencyGoal })
    transparencyTween:Play()

    transparencyTween.Completed:Wait() -- Wait for the tween to complete

    parts[1]:Destroy()
end)

–Forgot the t

this script gave me this error

02:14:05.105 Players.treeisnotcool.Backpack.part spawner.Server:18: attempt to call a nil value - Server - Server:18

I fixed it. Just forgot the t on insert

now its giving me this error… 02:16:11.899 Unable to cast value to Object - Server - Server:36

Just try getting it to print out the “Parts” value