Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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

0
Please put it in a code block. User#24403 69 — 5y
0
You asked a question yesterday and I linked a page. User#24403 69 — 5y

1 answer

Log in to vote
0
Answered by
xPolarium 1388 Moderation Voter
5 years ago
Edited 5 years ago

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.

Ad

Answer this question