Reputation: 35
Recently, I have been experimenting in the Roblox version of Lua in the studio. I tried to hook up a moving projectile to a GUI button. Here is the code:
local cannonp1 = workspace.CannonP1
local loopingvar = 0
script.Parent.MouseButton1Click:Connect(fire)
function fire()
repeat until loopingvar == 100
workspace.ProjectileP1.CFrame = workspace.ProjectileP1.CFrame * CFrame.new(1, 0, 0)
loopingvar = loopingvar + 1
wait(0.1)
end
end
I am very new to Roblox Studio, so all I can say is that When I press the button, not a single thing happens to my projectile. And the projectile is anchored, if you were wondering. I know that good questions should be elaborate, but there is no other information that i can find that would effect the movement of the projectile other than my extremely poor scripting. I have also checked on the Roblox developer forums, but most of the posts about CFrame there are outdated and do not work in the new version of Roblox Studio. I have checked about every website possible, but to no avail. Any advice would be amazing.
Upvotes: 0
Views: 64
Reputation: 48572
You're not using repeat until
correctly. The first line is supposed to be repeat
and the last line is supposed to be until loopingvar == 100
. There's not supposed to be an end
at all. Currently, there's a syntax error in your code due to the extra end
, and even without that, you'd have an infinite loop, since it's basically repeat --[[do nothing]] until loopingvar == 100
.
However, you can do even one step better than this, by using a numeric for
loop. Instead of the above changes, get rid of local loopingvar = 0
and loopingvar = loopingvar + 1
, and replace repeat until loopingvar == 100
with for loopingvar = 0,100 do
.
Upvotes: 1