I've decided to take a break from my next big game (since there were like a thousand errors that you guys didn't help me on.) so now i'm working on this Gui that allows you to change your camera mode. Here is how it looks like: StarterGui>CameraModeGui>ScrollingFrame>ShoulderCam>LocalScript OldRobloxCam>LocalScript (the newline is for the two objects in the same parent) so here is the first localscript:
local plr = game.Players.LocalPlayer local mouse = plr:GetMouse() local hit = mouse.Hit function Onhit(hit) workspace.CurrentCamera.CameraSubject = plr.Character["Right arm"] end
the second one is:
local plr = game.Players.LocalPlayer local mouse = plr:GetMouse() local hit = mouse.Hit function Onhit(hit) workspace.CurrentCamera.CameraSubject = plr.Character.Head end
ok, heres the problem; when I tested it out in solo,(doesn't matter) I clicked on the first one and nothing happened.I clicked the second one but it had the same problem. I looked in the output and got:
19:24:19.065 - Plugin attempting to show toolbar that does not exist - 96 19:24:19.105 - Unable to load plugin icon. Image may have an invalid or unknown format. Cutscene Editor Loaded
Jojomen56's Utility Plugin successfully loaded.
Mind the errors, if i fix it, you wont be able to use studio tools, sorry if it bugs you! 19:24:25.469 - Plugin_144711773.ArmorMaker.Script:41: attempt to index global 'gui' (a nil value) 19:24:25.470 - Stack Begin 19:24:25.470 - Script 'Plugin_144711773.ArmorMaker.Script', Line 41 19:24:25.471 - Stack End
19:24:25.471 - Disconnected event because of exception
Mind the errors, if i fix it, you wont be able to use studio tools, sorry if it bugs you! 19:24:25.472 - Plugin_144711773.ArmorMaker.Script:25: attempt to index global 'gui' (a nil value) 19:24:25.472 - Stack Begin 19:24:25.473 - Script 'Plugin_144711773.ArmorMaker.Script', Line 25 - global Off 19:24:25.473 - Script 'Plugin_144711773.ArmorMaker.Script', Line 11 19:24:25.473 - Stack End 19:24:25.474 - Disconnected event because of exception 19:24:25.474 - Unable to create an Instance of type "StockSound" 19:24:25.475 - Script '[string "--RoFinder Runtime Source..."]', Line 2442 19:24:25.475 - Stack End 19:30:22.364 - Auto-Saving...
Since that has nothing to do with my problem, I don't know what the problem is. (Every script I make acts like it's not there.) Could someone please point out to me the problem?
Thanks for reading!
A connection line is a line that contains the 'connect' method to call your function, whether or not it is anonymous.
In this example, when the Parent of the script is touched, it will trigger the 'example' function.
function example(argument) -- Content end script.Parent.Touched:connect(example)
The formula to call a function with the 'connect' method is this:
Function Anonymous Function end)
Just in case if you're asking, an anonymous function is simply a function without a name.
In the aforementioned example, this is how an anonymous function is laid out:
script.Parent.Touched:connect(function (argument) -- Content end
Going back to your script, here's a possible solution you may consider using to fix your script:
repeat wait(.5) until game.Players.LocalPlayer ~=nil local plr = game.Players.LocalPlayer local mouse = plr:GetMouse() local hit = mouse.Hit function Onhit(hit) if plr.Character:FindFirstChild("Right arm") then -- I added this statement just in case if there is no right arm workspace.CurrentCamera.CameraSubject = plr.Character:FindFirstChild("Right arm") else return nil end end function Onhit2(hit) if plr.Character:FindFirstChild("Head") then -- I added this statement just in case if the head is removed; this will not return any errors workspace.CurrentCamera.CameraSubject = plr.Character:FindFirstChild("Head") else return nil end end script.Parent.TextButton.MouseButton1Down:connect(OnHit) script.Parent.TextButton2.MouseButton1Down:connect(OnHit2) -- Adjust the location and/or identity of the button(s) to your desire
The reason why I put both of the functions in one script is because the script is more efficient space-wise and both of the functions can work in one script.