Im trying to make a script where it finds yourplayer then sits you down. But its not working in studio. This script is a localscript
1 | player_name = game.Players.LocalPlayer.Name |
2 | character = workspace:findFirstChild(player_name) |
3 |
4 | while true do |
5 | character.Humanoid.Sit = true |
6 | wait( 0.5 ) |
7 | end |
Local Script
1 | repeat wait() until game.Players.LocalPlayer.Character |
2 |
3 | while true do |
4 | game.Players.LocalPlayer.Character.Humanoid.Sit = true |
5 | wait(. 5 ) |
6 | end |
Well, we don't need the player name for this example. So we can rule that out. We can also create a short reference to the character by indexing LocalPlayer with "Character".
Here, try this:
01 | -- Get the local player (should be in a local script) |
02 | local Client = game:GetService 'Players' .LocalPlayer |
03 |
04 | -- just in case the character needs time to load |
05 | local Character = Client.Character or Client.CharacterAdded:wait() |
06 |
07 | while true do |
08 | local Human = Character:FindFirstChild 'Humanoid' |
09 | if Human then |
10 | Human.Sit = true |
11 | end |
12 | wait( 0.5 ) |
13 | end |
Let me know if you have any questions.