Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i repeat?

player=game.Players.LocalPlayer
mouse=player:GetMouse()

function KeyPressed(key)
	if key=="w" then
	while true do
	script.Parent:TweenPosition(UDim2.new(1, -211 , 1, -212), "In", "Linear", 0.5, false, nil)<--- trying to repeat this
	wait(0)
	script.Parent:TweenPosition(UDim2.new(1, -210 , 1, -210), "In", "Linear", 0.5, false, nil)<--- trying to repeat this
	end
	end
end

mouse.KeyDown:connect(KeyPressed)

the arrows are pointing to the things that I'm trying to keep repeating

2 answers

✓ Accepted answer

You're quite close, but there's two things.

  1. You're wait is too short. The interpolate functions are not callbacks, meaning your script will not wait for them to be finished. There's an easy solution to that, just add in a wait with the same time your animation takes.

  2. Once the key w is pressed, the animation will go on forever, even when the user releases key w. You'll have to add a check for that.

player=game.Players.LocalPlayer
mouse=player:GetMouse()
wDown = false

function KeyPressed(key)
    if key=="w" then
    wDown = true
    while wDown do
        script.Parent:TweenPosition(UDim2.new(1, -211 , 1, -212), "In", "Linear", 0.5, false)
        wait(0.5)
        script.Parent:TweenPosition(UDim2.new(1, -210 , 1, -210), "In", "Linear", 0.5, false)
        wait(0.5)
    end
    end
end

function KeyReleased(key)
    if key=="w" then
        wDown = false
    end
end

mouse.KeyDown:connect(KeyPressed)
mouse.KeyUp:connect(KeyReleased)

function generatepart(name,isAnchored,Trans) local part = Instance.new("Part") part.Name = name part.BrickColor = BrickColor.new("Really red") part.Anchored = isAnchored part.Position = Vector3.new(0,15,0) part.Size = Vector3.new(5,5,5) part.Parent = workspace part.Transparency = Trans end

generatepart("PartNumberOne",true,0) -- You have to put name,anchored, and trans all in these bractes -- generatepart("PartNumberTwo",false,0.3) generatepart("PartNumberThree",true,0.6)

This discussion is preserved as it was. New answers, comments, and votes are closed.