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

How to access character in workspace?

Asked by 5 years ago

I'm attempting to create a game where you press a button and it changes the size of your players head using the headscale value. So far what I've got is

1function KeyPress(input, gameProcessed)
2    if input.KeyCode == Enum.KeyCode.T then
3        game.Workspace._____________________???
4    end
5end
6 
7game:GetService("UserInputService").InputBegan:Connect(KeyPress)

what I need help is with how do you get to your player in workspace?

0
is this being done in a local or server script? speedyfox66 237 — 5y
0
It's a local script in starter pack Frostmaniz 4 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

With local scripts, you have access to the LocalPlayer, which you can get with

1--LocalScript
2local plr = game.Players.LocalPlayer

With any player instance, you can get their character with

1local character = plr.Character
2--Or alternatively...
3local character = game.Players.LocalPlayer.Character

So your code would be...

1local plr = game.Players.LocalPlayer
2local character = plr.Character
3function KeyPress(input, gameProcessed)
4    if input.KeyCode == Enum.KeyCode.T then
5        char.Head.Size = --put size here or somethin
6    end
7end
8 
9game:GetService("UserInputService").InputBegan:Connect(KeyPress)

Unless you wanted to use workspace...

1local plr = game.Players.LocalPlayer
2function KeyPress(input, gameProcessed)
3    if input.KeyCode == Enum.KeyCode.T then
4        game.Workspace[plr.Name].Head
5    end
6end

Hope this helps!

Ad

Answer this question