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

Can anyone help me with this spawn script?(Lua)

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.
player = game.Players.LocalPlayer

function SpawnPlayer()
    local spawns = Workspace["Spawn Players"]:WaitForChild("Spawnz"):GetChildren()
for _, player in pairs[contestants] do
if player and player.Character and #spawns > 0 then
torso = player.Character:WaitForChild("Torso")
local spawnedIndex = math.random(1, #spawns)
local spawn = spawns[spawnIndex]
if spawn and torso then
table.remove(spawns, spawnedIndex)
torso.CFrame = CFrame.new(spawn.Position = Vector3.new(0,3,0))
end

if player ~= nil then
    player.Character.Humanoid.Died:connect(SpawnPlayer)
else
    game.Players.PlayerAdded:connect(SpawnPlayer)
end

Where It Says torso.CFrame = CFrame.new(spawn.Position = Vector3.new(0,3,0)) the = sign keep going on red Idk why plus I get an error, can anyone of you pro scripters Help?

1
This isn't to answer your question but putitng (lua) is not needed this entire site is for lua Prioxis 673 — 9y
0
Ok :C Meh didn't know that but thank doe. :D IIxWhiteRobotxII 0 — 9y

2 answers

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

You are not trying to change (assign to) the SpawnLocation's position, so = doesn't make sense here.


(Even if you did mean to do that, doing assignment in the middle of another assignment isn't allowed in Lua -- it would have to be done separately, either before or after setting the Torsos' CFrame)


You probably meant to type + to add 3 studs upwards to the SpawnLocation's position.



As an aside, you should really tab and space your code better. It makes it much easier to read and understand.

0
How did you make those lines between the paragraphs? Perci1 4988 — 9y
Ad
Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

So what are you trying to do? Are you trying to change the position of the torso, setting it to three studs above the spawn's position,

torso.CFrame = CFrame.new(spawn.Position + Vector3.new(0,3,0))

or are you trying to change the spawn's position itself?

spawn.Position = Vector3.new(0,3,0)

Assuming you want to do the former, to add something in Lua you use a + sign. This seems kind of obvious to me, but if you take one Vector3 and add another Vector3, you use a +, not an =, to indicate you want Lua to add the values.

Answer this question