I have a script, when the player joins their camera will focus on a piece until they press a button, it works exactly how I want it to work, except in Roblox Player itself! Why is that happening? here is my script
wait(1) repeat wait(1) if workspace:findFirstChild("Player") then if script.Parent.Value == 1 and script.Parent.Parent.CamValue.Value == 1 then Workspace.Player.Torso.CFrame = CFrame.new(Workspace.Spawners.WhiteSpawn.Position + Vector3.new(0, 2, 0)) elseif script.Parent.Value == 2 and script.Parent.Parent.CamValue.Value == 1 then Workspace.Player.Torso.CFrame = CFrame.new(Workspace.Spawners.GraySpawn.Position + Vector3.new(0, 2, 0)) elseif script.Parent.Value == 3 and script.Parent.Parent.CamValue.Value == 1 then Workspace.Player.Torso.CFrame = CFrame.new(Workspace.Spawners.BlackSpawn.Position + Vector3.new(0, 2, 0)) end end until script.Parent.Parent.CamValue.Value == 0
Please help!!! Thank you!!! P.S. Should this be in regular or local script?
First of all, fix your formatting. Indent each line appropriately, because it could get confusing to look at.
repeat wait(1) if workspace:findFirstChild("Player") then if script.Parent.Value == 1 and script.Parent.Parent.CamValue.Value == 1 then workspace.Player.Torso.CFrame = CFrame.new(workspace.Spawners.WhiteSpawn.Position + Vector3.new(0, 2, 0)) elseif script.Parent.Value == 2 and script.Parent.Parent.CamValue.Value == 1 then workspace.Player.Torso.CFrame = CFrame.new(workspace.Spawners.GraySpawn.Position + Vector3.new(0, 2, 0)) elseif script.Parent.Value == 3 and script.Parent.Parent.CamValue.Value == 1 then workspace.Player.Torso.CFrame = CFrame.new(workspace.Spawners.BlackSpawn.Position + Vector3.new(0, 2, 0)) end end until script.Parent.Parent.CamValue.Value == 0
Let's make some variables to assess the situation more efficiently.
CamValue = script.Parent.Parent:WaitForChild("CamValue") SomeRandomValue = script.Parent WhiteSpawnPos = workspace.Spawners.WhiteSpawn.Position GraySpawnPos = workspace.Spawners.GraySpawn.Position BlackSpawnPos = workspace.Spawners.WhiteSpawn.Position repeat wait(1) if workspace:findFirstChild("Player") then if SomeRandomValue.Value == 1 and CamValue.Value == 1 then workspace.Player.Torso.CFrame = CFrame.new(WhiteSpawnPos + Vector3.new(0, 2, 0)) elseif SomeRandomValue.Value == 2 and CamValue.Value == 1 then workspace.Player.Torso.CFrame = CFrame.new(GraySpawnPos + Vector3.new(0, 2, 0)) elseif SomeRandomValue.Value == 3 and CamValue.Value == 1 then workspace.Player.Torso.CFrame = CFrame.new(BlackSpawnPos + Vector3.new(0, 2, 0)) end end until CamValue.Value == 0
The main problem I see with this script is on line 5, if there's "Player" in the workspace. Now, I'm pretty sure your user name is "yogipanda123", not "Player".
"Player" is the name of the testing player spawned in solo mode. If you want the script to work in the server, refer each player as its own with...
game.Players.LocalPlayer
(Note: LocalPlayer can only be mentioned in Local Scripts.)
repeat wait(.1) until game.Players.LocalPlayer PLR = game.Players.LocalPlayer -- Since you want to use the Torso's (which is located in the character of the player) position, I'd recommend for you to do this: CHAR = PLR.Character if not CHAR then CHAR = PLR.CharacterAdded:wait(.1) end Torso = CHAR:WaitForChild("Torso")
Now, let's continue on to your "repeat" loop.
repeat wait(1) if SomeRandomValue.Value == 1 and CamValue.Value == 1 then Torso.CFrame = CFrame.new(WhiteSpawnPos + Vector3.new(0, 2, 0)) elseif SomeRandomValue.Value == 2 and CamValue.Value == 1 then Torso.CFrame = CFrame.new(GraySpawnPos + Vector3.new(0, 2, 0)) elseif SomeRandomValue.Value == 3 and CamValue.Value == 1 then Torso.CFrame = CFrame.new(BlackSpawnPos + Vector3.new(0, 2, 0)) end until CamValue.Value == 0
This should be a working script. Place this in StarterGui and test it out. I would love to mention other ways to make this, but to do that I would have to know the whole script(s), the purpose of SomeRandomValue
, and how will the value of CamValue reach 0.