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

player_name=game.Players.LocalPlayer.Name
character=workspace:findFirstChild(player_name)

while true do
    character.Humanoid.Sit = true
    wait(0.5)
end

2 answers

Log in to vote
1
Answered by 9 years ago

Local Script

repeat wait() until game.Players.LocalPlayer.Character

while true do
game.Players.LocalPlayer.Character.Humanoid.Sit = true
wait(.5)
end

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:

-- Get the local player (should be in a local script)
local Client = game:GetService'Players'.LocalPlayer

 -- just in case the character needs time to load
local Character = Client.Character or Client.CharacterAdded:wait()

while true do
    local Human = Character:FindFirstChild'Humanoid'
    if Human then
        Human.Sit = true
    end
    wait(0.5)
end

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