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

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

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?

2 comments

1

This isn't to answer your question but putitng (lua) is not needed this entire site is for lua

0

Ok :C Meh didn't know that but thank doe. :D

2 answers

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.

1 comment

0

How did you make those lines between the paragraphs?

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.

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