Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

LocalScript that Loads your Character & Resets your camera works only in studio?

I have no idea why this isn't working, the script below is supposed to trigger when a ScreenGui Button is clicked. It resets your camera and respawns your character, but it isn't working on a live server, whilst in studio, it works perfectly.

function onClicked()
game.Workspace.CurrentCamera.CameraSubject = 					game.Players.LocalPlayer.Character.Humanoid
game.Workspace.CurrentCamera.CameraType = "Custom"
game.Players.LocalPlayer:LoadCharacter()
script.Parent.MouseButton1Down:connect(onClicked)

4 comments

0

Maybe you're not giving enough time for your script to load, try adding a wait() at the beginning.

0

Does your game implement Filtering Enabled?

0

Adding wait() at the top of your scripts is really ugly.

0

You're missing an end btw, and a connection to the function

1 answer

If your game has Filtering Enabled then that's a whole other answer. If you don't have it Enabled then this will work. As said above your not giving enough time for your script to load. In this case, we use WaitForChild on variables or straight to the function.

I will fix the script and tell you what I added

Fix;

function onClicked()
game.Workspace.CurrentCamera.CameraSubject =              game.Players.LocalPlayer.Character:WaitForChild("Humanoid") -- added wait for child
game.Workspace.CurrentCamera.CameraType = "Custom"
game.Players.LocalPlayer:LoadCharacter()
script.Parent.MouseButton1Down:connect(onClicked)

Here's a few stuff to look out! If it still doesn't work try adding WaitForChild for the humanoid. if it still doesn't work after that then add WaitForChild on CurrentCamera as well. This is how you use wait for child functions

example; game.Players.LocalPlayer.Character you add : then WaitForChild("Name") there's also an example above in the fixed script.

Make sure you accept the answer and upvote if worked/helped

Any questions? Ask below! I will get back to you right away!

This discussion is preserved as it was. New answers, comments, and votes are closed.