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

Specate tool gui problems. No idea what im doing help?

So I legit have no idea what i am doing BUT. Let me try to explain. I'm trying to do it so that when a person clicks on a gui it should focus on a tool, whether it's in another players backpack or in the workspace.

script.Parent.MouseButton1Click:Connect(function(player)
	if game.Players.LocalPlayer.Backpack:FindFirstChild("Tool") or workspace:WaitForChild("Tool") then
		local cam = workspace.CurrentCamera
		cam.CameraSubject = game.Players.LocalPlayer.Backpack:FindFirstChild("Tool") or workspace:WaitForChild("Tool")
		cam.CameraType = "Follow"
	end
end)

here is what i tried xd

1 comment

0

I posted an answer, I think my answer should help.

2 answers

 script.Parent.MouseButton1Click:Connect(function(player)
2	    if game.Players.LocalPlayer.Backpack:FindFirstChild("Tool") or workspace:WaitForChild("Tool") then
3	        local cam = workspace.CurrentCamera
4	        cam.CameraSubject = game.Players.LocalPlayer.Backpack:FindFirstChild("Tool") or workspace:WaitForChild("Tool")
5	        cam.CameraType = "Follow"
6	    end
7	end)

I think that I have found your problem, It is because you putted two ends, you putted one at the 6 and one at the 7 maybe try to remove the 6 but put the 7 at th six example:

script.Parent.MouseButton1Click:Connect(function(player)
2	    if game.Players.LocalPlayer.Backpack:FindFirstChild("Tool") or workspace:WaitForChild("Tool") then
3	        local cam = workspace.CurrentCamera
4	        cam.CameraSubject = game.Players.LocalPlayer.Backpack:FindFirstChild("Tool") or workspace:WaitForChild("Tool")
5	        cam.CameraType = "Follow"
6	end)


1 comment

0

theres an if statment

###The reason for this is because the CameraSubject property only accepts Instances of the classes Humanoid and PVInstance, and inheritors of said classes. So things like Models and BaseParts can be the value for the CameraSubject property. Luckily, Tools need a Handle BasePart, if your tool requires it. So simply set the CameraSubject to the Handle of the tool.

local client = game.Players.LocalPlayer
local cam = workspace.CurrentCamera
local character = client.Character
-- Don't repeat yourself! Have a variable for the player, character and camera. 

script.Parent.Activated:Connect(function() -- MouseButton1Click passes no player! Use Activated instead though. 

    if client.Character:FindFirstChild("Tool") or workspace:FindFirstChild("Tool") then
       
        cam.CameraSubject = client.Character:FindFirstChild("Tool").Handle or workspace:FindFirstChild("Tool").Handle
        cam.CameraType = Enum.CameraType.Follow
    end
end)

###I also modified the script so it looks for Tool in the character instead of the backpack, as it would not show if it was in the backpack.

####Hope this helped!

2 comments

0

yeah but that's the thing I want it so that when u click a gui it would spectate any tool whether its in a person backpack or in the workspace

0

also has an error (Players.WillBe_Stoped.PlayerGui.ScreenGui.TextButton.LocalScript:10: attempt to index a nil value)

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