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

Why does this camera LocalScript only work in studio and not online? It's in a gui

Asked by 7 years ago
Edited 7 years ago

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)
0
The cam might not exist yet when the variable is being made. Try using 'local cam = game.Workspace:WaitForChild("CurrentCamera")' saenae 318 — 7y
0
Didn't work, thanks for the reply tho greybird700 63 — 7y
0
CurrentCamera should already exist on the client. Try adding a WaitForChild for one of your items in the box variable instead. Spongocardo 1991 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

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

0
Thank you so much for replying but it doesn't work, it's giving me an error because of the second local box greybird700 63 — 7y
0
But even deleting the second one it still doesn't work greybird700 63 — 7y
0
if it's the error because of the second line then fix it to the right variable then everything will work. It was meant to work all togeather BlackOrange3343 2676 — 7y
0
There's no error with the parenting or anything I don't understand why it still doesn't work but I will accept your answer because you've actually tried to help me! any further help with this would be greatly appreciated :) greybird700 63 — 7y
Ad

Answer this question