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

Can somebody help me to short this script? I need to make more lines of it and it will take a while.

game.Workspace.IWillSaveYourDay.HumanoidRootPart.CFrame = CFrame.new(workspace.Checkpoints["1"].Position) game.Workspace.IWillSaveYourDay.HumanoidRootPart.CFrame = CFrame.new(workspace.Checkpoints["2"].Position) game.Workspace.IWillSaveYourDay.HumanoidRootPart.CFrame = CFrame.new(workspace.Checkpoints["3"].Position) game.Workspace.IWillSaveYourDay.HumanoidRootPart.CFrame = CFrame.new(workspace.Checkpoints["4"].Position) game.Workspace.IWillSaveYourDay.HumanoidRootPart.CFrame = CFrame.new(workspace.Checkpoints["5"].Position) game.Workspace.IWillSaveYourDay.HumanoidRootPart.CFrame = CFrame.new(workspace.Checkpoints["6"].Position) game.Workspace.IWillSaveYourDay.HumanoidRootPart.CFrame = CFrame.new(workspace.Checkpoints["7"].Position) game.Workspace.IWillSaveYourDay.HumanoidRootPart.CFrame = CFrame.new(workspace.Checkpoints["8"].Position) game.Workspace.IWillSaveYourDay.HumanoidRootPart.CFrame = CFrame.new(workspace.Checkpoints["9"].Position) game.Workspace.IWillSaveYourDay.HumanoidRootPart.CFrame = CFrame.new(workspace.Checkpoints["10"].Position) game.Workspace.IWillSaveYourDay.HumanoidRootPart.CFrame = CFrame.new(workspace.Checkpoints["11"].Position) game.Workspace.IWillSaveYourDay.HumanoidRootPart.CFrame = CFrame.new(workspace.Checkpoints["12"].Position) game.Workspace.IWillSaveYourDay.HumanoidRootPart.CFrame = CFrame.new(workspace.Checkpoints["13"].Position) game.Workspace.IWillSaveYourDay.HumanoidRootPart.CFrame = CFrame.new(workspace.Checkpoints["14"].Position) game.Workspace.IWillSaveYourDay.HumanoidRootPart.CFrame = CFrame.new(workspace.Checkpoints["15"].Position) game.Workspace.IWillSaveYourDay.HumanoidRootPart.CFrame = CFrame.new(workspace.Checkpoints["16"].Position) game.Workspace.IWillSaveYourDay.HumanoidRootPart.CFrame = CFrame.new(workspace.Checkpoints["17"].Position) game.Workspace.IWillSaveYourDay.HumanoidRootPart.CFrame = CFrame.new(workspace.Checkpoints["18"].Position) game.Workspace.IWillSaveYourDay.HumanoidRootPart.CFrame = CFrame.new(workspace.Checkpoints["19"].Position) game.Workspace.IWillSaveYourDay.HumanoidRootPart.CFrame = CFrame.new(workspace.Checkpoints["20"].Position)

1 comment

0

Format your code correctly, and use a function or a for loop instead of copy and pasting it

3 answers

Hi -- What you need is a for loop. It'll repeat your code for the amount of times there are checkpoints. Here's a concept of it:

for i = 1,#checkpoints do
	game.Workspace.IWillSaveYourDay.HumanoidRootPart.CFrame = CFrame.new(workspace.Checkpoints[tostring(i)].Position)
end

I wrote this in about 20 seconds, but it's something to start off of. Not 100% sure if the tostring is required, but experiment with it a little

4 comments

0

i got this Players.IWillSaveYourDay.PlayerScripts.LocalScript:2: attempt to get length of a nil value

0

Is the code running as soon as the player spawns, or is it running after an event runs, after double-checking the player exists?

0

^also, you'd have to define a couple things before running my code -- I only gave you a concept

0

Use an in pairs loop instead of a for loop.

The following script will set it to all the Checkpoints from 1 to 20.

for i = 1, 20 do
	 game.Workspace.IWillSaveYourDay.HumanoidRootPart.CFrame = CFrame.new(workspace.Checkpoints[tostring(i)].Position)
end

Although if you want the movement to look smooth, you could tween or lerp the cframe instead or add some form of wait inbetween the checkpoints.

1 comment

0

Thanks master\

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