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
01 | local Button = script.Parent |
02 | local Box = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.ActualHats.Frame.PirateHatz |
03 | local cam = game.workspace.CurrentCamera |
04 | function OnButtonClick() |
05 | Box.Visible = true |
06 | cam.CameraSubject = game.workspace.StoreWall |
07 | cam.CameraType = "Attach" |
08 | end |
09 |
10 | script.Parent.MouseButton 1 Down: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;
01 | local B = script.Parent -- B stands for Button |
02 | 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 |
03 | local cam = game.Workspace:WaitForChild( 'CurrentCamera' ) --Cap W and added WaitForChild |
04 | local SW = game.Workspace:WaitForChild( 'StoreWall' ) -- new variable |
05 |
06 | B.MouseButton 1 Down:Connect( function () --Don't use connect use Connect and u don't need to call a function |
07 | Box.Visible = true |
08 | cam.CameraSubject = SW |
09 | cam.CameraType = "Attach" |
10 | 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