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

script cant find a part except that part already exists?

I have this part that creates itself and names itself after the player who joined the game, but when the camera script tries to set the camera to it, it says it cant find it even though it says the name of the object its trying to find except the object is in the workspace.

function Joined(Player)
	x = Instance.new("Part")
	x.Shape = "Ball"
	x.Parent = game.Workspace
	x.Name = Player.Name .. "'s Ball"
	x.Material = "Neon"
	x.Color = Color3.new(math.random(), math.random(), math.random())
	x.Position = workspace.Start.Position
	x.CanCollide = true
	x.Anchored = false
	x.Size = Vector3.new(1, 1, 1)
	end

game.Players.PlayerAdded:connect(Joined)
wait(1)
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera
local playername = Player.Name .. "'s Ball"
print(playername)
wait(1)

repeat wait()
	Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable
Camera.CFrame = workspace(playername).CFrame

1 answer

You use square brackets for indexing

Camera.CFrame = workspace[playername].CFrame

Or, preferably, WaitForChild as it waits for it to appear on the workspace:

Camera.CFrame = workspace:WaitForChild(playername).CFrame -- use this instead.

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