I've tried to change this script countless times to make it work online, but it doesn't, I don't understand why it doesn't work because it's in a local script. BTW, there's nothing wrong with the box part, it's the camera part that isn't working -- works fine in studio though
local Button = script.Parent local Box = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.ActualHats.Frame.PirateHatz local cam = game.workspace.CurrentCamera function OnButtonClick() Box.Visible = true cam.CameraSubject= game.workspace.StoreWall cam.CameraType = "Attach" end script.Parent.MouseButton1Down:connect(OnButtonClick)
Lot's of people have the same problem, there scripts works in Studio but no game. Why? Because the assets haven't been loaded yet. So that means when you say something like
local part = game.Workspace.Part
chances are "Part" hasn't loaded and part would be basically nothing. A few ways to fix this is by adding :WaitForChild()
To variables or wait()
from the beginning of the script which is not cool.
I will help you edit your code that includes :WaitForChild()
and also some edit to make it a better script it self;
local B = script.Parent -- B stands for Button local Box = local Box = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent:WaitForChild('ActualHats').Frame.PirateHatz -- the reason I used WaitForChild on actual hats because actual hats is the parent and so if parent is loaded child is loaded as well local cam = game.Workspace:WaitForChild('CurrentCamera') --Cap W and added WaitForChild local SW = game.Workspace:WaitForChild('StoreWall') -- new variable B.MouseButton1Down:Connect(function() --Don't use connect use Connect and u don't need to call a function Box.Visible = true cam.CameraSubject= SW cam.CameraType = "Attach" end)
This SHOULD work but if it doesn't comment down below and tell me if theres a error if it worked or you somehowly figured out how to make it work then please accept answer ;)
Have Fun and Good Luck Developing!
--BlackOrange3343