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

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

Asked by 7 years ago

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)
0
Maybe you're not giving enough time for your script to load, try adding a wait() at the beginning. strongrussianboy123 68 — 7y
0
Does your game implement Filtering Enabled? Troidit 253 — 7y
0
Adding wait() at the top of your scripts is really ugly. OldPalHappy 1477 — 7y
0
You're missing an end btw, and a connection to the function OldPalHappy 1477 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

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!

Ad

Answer this question