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

I ran my script but my output said this function arguments expected near 'for'. Some help?

function tp() local players = game.players:GetPlayers() local parts = game.Workspace.Parts:GetChildren for 1 = 1,#players do players(1).Character.HumanoidRootPart.CFrame = game.Workspace.Part.CFrame + Vector3.new(0,3,0) end end

while wait(3) do tp() end

2 comments

0

Please put it in a code block.

0

You asked a question yesterday and I linked a page.

1 answer

Please properly format code you're including when opening a question. You can see how to do that here.

Your code:

function tp() 
	local players = game.players:GetPlayers() 
	local parts = game.Workspace.Parts:GetChildren 
	
	for i = 1,#players do 
		players(1).Character.HumanoidRootPart.CFrame = game.Workspace.Part.CFrame + Vector3.new(0,3,0) 
	end 
end

while wait(3) do 
	tp() 
end

The issue is the following error from output:

function arguments expected near 'for'

The issue is that on line 3, you didn't provide parenthesis to the :GetChildren() function. When using a function, like GetChildren(), you need to provide the parenthesis.

local parts = workspace.Parts:GetChildren()

In your for loop, you call your variable '1'? It would make sense to use something like i to define a variable.

You also are trying to index a player using parenthesis. To index something from a table you use brackets -> [key]

players[i].Character.HumanoidRootPart.CFrame = workspace.Part.CFrame + Vector3.new(0,3,0) 

Your finished code should be something like:

function tp() 
	local players = game.Players:GetPlayers() 
	local parts = workspace.Parts:GetChildren()
	
	for i = 1,#players do 
		players[i].Character.HumanoidRootPart.CFrame = workspace.Part.CFrame + Vector3.new(0,3,0) 
	end 
end

--Don't do while wait() do
--Know that this is an infinite loop too!
while true do 
	--tp first then wait 3 seconds
	tp() 
	wait(3)
end

Edit: Overlooked spelling mistakes in your code and is now fixed in final. You also use game.Workspace.Model when you could just use workspace.Model.

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