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

Please Help and Fix this for me!?

What's Wrong With Line 5?!?!?!

spawn = game.Workspace.SpawnLocation
player = script.Parent.Parent.Parent.Parent

function onClicked
	player.Character:MoveTo(spawn.Position) -- '(' expected near 'player'
end

script.Parent.MouseButton1Down(onClicked)
for index, player in pairs(game.Players:GetPlayers()) do
print(player.Name)
end

My previous question was my Teleport GUI Help and it wasn't answered quite right or I just didn't understand the script. The Script that I made:

spawn = game.Workspace.SpawnLocation
player = script.Parent.Parent.Parent.Parent

function onClicked
    player.Character:MoveTo(spawn.Position)
end

script.Parent.MouseButton1Down(onClicked)

But then yumtaste (who answered my question) said to incorporate this:

for index, player in pairs(game.Players:GetPlayers()) do
print(player.Name)
end

to my script but I'm having trouble. Can you please help me? I need a complete script ASAP. Thx guys!

3 comments

0

You are using the function incorrectly, or, as I should say, typed it incorrectly, on line 4.

0

So what should it be?

0

You did not add the parentheses, or the '()' things, I should say.

1 answer

✓ Accepted answer

Your top code should be more around this - You merely had a syntax error:

spawn = workspace.SpawnLocation
player = script.Parent.Parent.Parent.Parent

function onClicked()
    player.Character:MoveTo(spawn.Position)
end

script.Parent.MouseButton1Down:connect(onClicked)
--[[
for index, player in pairs(game.Players:GetPlayers()) do
print(player.Name)
end]]-- I don't see a use for this segment of code


I'd also recommend using a local-script for what you are trying to achieve.

IF YOU USE A LOCALSCRIPT:

spawn = workspace["SpawnLocation"]
plr = game.Players.LocalPlayer or game.Players.LocalPlayer:wait()

script.Parent.MouseButton1Down:connect(function()
plr.Character:MoveTo(spawn.Position)
end)

1 comment

0

No need to wait for the LocalPlayer, it will always exist. I'm also pretty sure :wait() only works on events.

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