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

FPS/TPS script working fine in solo, yet not in the game? HELP!

I fixed the script! It works perfectly the way it should! Since the whole script is open source, here is the link to the model: http://www.roblox.com/FPS-TPS-Script-item?id=302280310

Or you can have the code (LocalScript in StarterPack):

local ToggleKey = "t"
local Player = game.Players.LocalPlayer
Player.CameraMode = Enum.CameraMode.LockFirstPerson
local Character = Player.Character or Player.CharacterAdded:wait()
wait(2.5)
local Mouse = Player:GetMouse()
local Camera = game.Workspace.CurrentCamera

local AM = Instance.new("Model", Camera)
local FakeParts = {}
AM.Name = "TPSBody"
Arms = {Player.Character["Left Arm"], Player.Character["Right Arm"]}
Arm1 = Instance.new("Part", AM)
Arm1.Name = "Left Arm"
Arm1.CanCollide = false
Arm1.FormFactor = Enum.FormFactor.Custom
Arm1.Size = Arms[1].Size - Vector3.new(0.1, 0.1, 0.1)
Arm1.BrickColor = Arms[1].BrickColor
table.insert(FakeParts, #FakeParts+1, Arm1)
Arm2 = Instance.new("Part", AM)
Arm2.Name = "Right Arm"
Arm2.CanCollide = false
Arm2.FormFactor = Enum.FormFactor.Custom
Arm2.Size = Arms[2].Size - Vector3.new(0.1, 0.1, 0.1)
Arm2.BrickColor = Arms[2].BrickColor
table.insert(FakeParts, #FakeParts+1, Arm2)
W1 = Instance.new("Weld", Arm1)
W1.Part0 = Arms[1]
W1.Part1 = Arm1
W2 = Instance.new("Weld", Arm2)
W2.Part0 = Arms[2]
W2.Part1 = Arm2
Legs = {Player.Character["Left Leg"], Player.Character["Right Leg"]}
Leg1 = Instance.new("Part", AM)
Leg1.Name = "Left Leg"
Leg1.CanCollide = false
Leg1.FormFactor = Enum.FormFactor.Custom
Leg1.Size = Legs[1].Size
Leg1.BrickColor = Legs[1].BrickColor
table.insert(FakeParts, #FakeParts+1, Leg1)
Leg2 = Instance.new("Part", AM)
Leg2.Name = "Right Leg"
Leg2.CanCollide = false
Leg2.FormFactor = Enum.FormFactor.Custom
Leg2.Size = Legs[2].Size
Leg2.BrickColor = Legs[2].BrickColor
table.insert(FakeParts, #FakeParts+1, Leg2)
W3 = Instance.new("Weld", Leg1)
W3.Part0 = Legs[1]
W3.Part1 = Leg1
W4 = Instance.new("Weld", Leg2)
W4.Part0 = Legs[2]
W4.Part1 = Leg2
Vitals = {Player.Character.Torso, Player.Character.Head}
Tors = Instance.new("Part", AM)
Tors.Name = "Torso"
Tors.CanCollide = false
Tors.FormFactor = Enum.FormFactor.Custom
Tors.Size = Vitals[1].Size
Tors.BrickColor = Vitals[1].BrickColor
table.insert(FakeParts, #FakeParts+1, Tors)
Head = Instance.new("Part", AM)
Head.Name = "FakeHead"
Head.CanCollide = false
Head.FormFactor = Enum.FormFactor.Custom
Head.Size = Vitals[2].Size
Head.BrickColor = Vitals[2].BrickColor
table.insert(FakeParts, #FakeParts+1, Head)
HeadMesh = Character.Head.Mesh:Clone()
HeadMesh.Parent = Head
HeadMesh.Scale = HeadMesh.Scale - Vector3.new(0.01, 0.01, 0.01)
W5 = Instance.new("Weld", Tors)
W5.Part0 = Vitals[1]
W5.Part1 = Tors
W6 = Instance.new("Weld", Head)
W6.Part0 = Vitals[2]
W6.Part1 = Head

Human = Instance.new("Humanoid", AM)
Human.Name = "FakeHumanoidFake"
print("Here's mah stuff")
for _,Obj in pairs(Player.Character:GetChildren()) do
	if Obj:IsA("CharacterMesh") or Obj:IsA("Shirt") or Obj:IsA("Pants") then
		Obj:Clone().Parent = AM
	end
	if Obj:IsA("Hat") then
		local NewHat = Obj:Clone()
		NewHat.Parent = AM
		table.insert(FakeParts, #FakeParts+1, NewHat.Handle)
		wait()
		local HatWeld = Instance.new("Weld", Head)
		HatWeld.Name = "HatWeld"
		HatWeld.Part0 = NewHat.Handle
		HatWeld.Part1 = Head
		NewHat.Handle.Mesh.Offset = Vector3.new(0, 0.1, 0)
	end
	wait()
end

Character.Humanoid.Died:connect(function()
	AM:Destroy()
	Character.Humanoid.CameraOffset = Vector3.new(0, 0, 0)
	connect:disconnect()
end)

for i,v in pairs(FakeParts) do
	v.Transparency = 1
end

print("Connecting the mouse...")

connect = Mouse.KeyDown:connect(function(key)
	if key == ToggleKey then
		if Character.Humanoid.CameraOffset == Vector3.new(0, 0, 0) then
			Character.Humanoid.CameraOffset = Vector3.new(1.5, 0.5, 5)
			for i,v in pairs(FakeParts) do
				v.Transparency = 0
			end
		elseif Character.Humanoid.CameraOffset == Vector3.new(1.5, 0.5, 5) then
			Character.Humanoid.CameraOffset = Vector3.new(0, 0, 0)
			for i,v in pairs(FakeParts) do
				v.Transparency = 1
			end
		end
	end
end)

Thanks for the help guys!

1 answer

You aren't defining character right. The reason it works in F5 is because the character is loaded before the script starts up, it doesn't work in F7/InGame because the character doesn't exist when the script runs.

local Character = Player.Character or Player.CharacterAdded:wait()

This defines character as player.Character if it isn't nil, otherwise it waits until the character is added and defines it as what player.CharacterAdded returns, which is the character.

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