Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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

0
I posted an answer, I think my answer should help. DjMusa2 81 — 6y

2 answers

Log in to vote
1
Answered by
DjMusa2 81
6 years ago
 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)


0
theres an if statment User#23365 30 — 6y
Ad
Log in to vote
1
Answered by 6 years ago

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!

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 WillBe_Stoped 71 — 6y
0
also has an error (Players.WillBe_Stoped.PlayerGui.ScreenGui.TextButton.LocalScript:10: attempt to index a nil value) WillBe_Stoped 71 — 6y

Answer this question