For i = loop problem

I tried making a simple power where the player shoots out 10 cans to the mouse pos via a loop. When the move is used, nothing happens yet it says the event has fired. Any help would be appreciated.

           local function Can()
                    local canclone = game:GetService("ReplicatedStorage").Models:FindFirstChild("Can"):Clone()
                    canclone.Parent = workspace
                    canclone.Position = char.HumanoidRootPart + Vector3.new(0,0,-5)
                    
                    local BodyVelocity = Instance.new("BodyVelocity", canclone)
                    BodyVelocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
                    BodyVelocity.Velocity = CFrame.new(canclone.Position, Mouse.p).lookVector * 100
            end

                for i = 0.3, repeat_times do
                    Can()
                end
1 Like

May I ask why you define variable ‘i’ as 0.3? Why don’t you define it with 1?

1 Like

You should provide the whole code as char and repeat_times are undefined here. The definition of repeat_times is likely your issue if the code doesn’t output any errors to the console.

1 Like

Is it necessary to say
local canclone = game:GetService("ReplicatedStorage").Models:FindFirstChild("Can"):Clone()

why not
local canclone = game.ReplicatedStorage.Models.Can:Clone()
just to make it easier on yourself.

The point of the instance FindFirstChild is to search for the asset inside of the Parent. game:GetService is used to return a service with the class name requested.

My mistake. I was rather confused as well when I saw the weird mistake I made. This fixed the problem. Thanks a lot! :grinning: