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

Why Can I Not Set Position?

Hello there. I have made this following script:

local SpawnOne = game.Workspace.SpawnOne
local SpawnTwo = game.Workspace.SpawnTwo
local SpawnThree = game.Workspace.SpawnThree
local SpawnFour = game.Workspace.SpawnFour
local Player = game.Players.LocalPlayer
local Player = Players.LocalPlayer
PlayerSpawn = math.random(1, 4)
print(PlayerSpawn)
if PlayerSpawn == 1 then
	Player.Position = Vector3.new(196, 119.5, 192.5)
end

if PlayerSpawn == 2 then
	Player.Position = Vector3.new(196, 119.5, -208.5)
end

if PlayerSpawn == 3 then
	Player.Position = Vector3.new(-186, 120.5, -208.5)
end

if PlayerSpawn == 4 then
	Player.Position = Vector3.new(-188, 121.5, 190.5)
end

When I play, I cannot go to the designated random spawnpoint. If there is any way I cac improve this script please tell me. It would also be nice just to fix it. Thanks!

1 answer

✓ Accepted answer

You seem a bit confused with Lua but I'll help I think it's easier to just CFrame the Torso, ofcourse you can just use MoveTo() or SetPrimaryPartCFrame() to move the model as well, but I'll do it the CFrame Torso way.

You seem to have made variable of the spawn parts so why not use them? Also, the script you have made will only work if you're using a LocalScript. No idea Why you defined Player twice so I removed the one that wouldn't work correctly. Also remember you are trying to move the Player, not the character which is WRONG, the Player has no location! Look bellow for the script and read the comments on how it functions!

wait(3) -- Make sure the character is loaded
local SpawnOne = game.Workspace.SpawnOne.CFrame
local SpawnTwo = game.Workspace.SpawnTwo.CFrame
local SpawnThree = game.Workspace.SpawnThree.CFrame
local SpawnFour = game.Workspace.SpawnFour.CFrame --Make the variables the CFrame so we can just us the variable instead of creating a new CFrame of the same position.
local Player = game.Players.LocalPlayer
local character = Player.Character -- Get the Character so we can move it

PlayerSpawn = math.random(1, 4)
print(PlayerSpawn)
if PlayerSpawn == 1 then
    character.Torso.CFrame = SpawnOne
end

if PlayerSpawn == 2 then
    character.Torso.CFrame = SpawnTwo
end

if PlayerSpawn == 3 then
    character.Torso.CFrame = SpawnThree
end

if PlayerSpawn == 4 then
    character.Torso.CFrame = SpawnFour
end

Please comment any questions you have, otherwise accept this answer if it helps!

2 comments

0

Hi, thanks for answering, but it still doesn't seem to be working. Something I would like to mention is that this is first off in Workspace, if that has anything to do with it. Also, the random number is not printing, so I don't know what to do about that. Thanks again, and I would really love a reply!

0

Make this a Local script and toss it in Backpack.

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