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

Why does this not sit my character?

Asked by 9 years ago

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

1player_name=game.Players.LocalPlayer.Name
2character=workspace:findFirstChild(player_name)
3 
4while true do
5    character.Humanoid.Sit = true
6    wait(0.5)
7end

2 answers

Log in to vote
1
Answered by 9 years ago

Local Script

1repeat wait() until game.Players.LocalPlayer.Character
2 
3while true do
4game.Players.LocalPlayer.Character.Humanoid.Sit = true
5wait(.5)
6end
Ad
Log in to vote
2
Answered by 9 years ago

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)
02local Client = game:GetService'Players'.LocalPlayer
03 
04 -- just in case the character needs time to load
05local Character = Client.Character or Client.CharacterAdded:wait()
06 
07while true do
08    local Human = Character:FindFirstChild'Humanoid'
09    if Human then
10        Human.Sit = true
11    end
12    wait(0.5)
13end

Let me know if you have any questions.

0
It does not work online or in studio :( LittleBigDeveloper 245 — 9y
0
Works fine for me, remember to put this in a local script. CodingEvolution 490 — 9y

Answer this question