Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to access character in workspace?

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

function KeyPress(input, gameProcessed)
    if input.KeyCode == Enum.KeyCode.T then
 		game.Workspace._____________________???
    end
end

game:GetService("UserInputService").InputBegan:Connect(KeyPress)

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

2 comments

0

is this being done in a local or server script?

0

It's a local script in starter pack

1 answer

✓ Accepted answer

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

--LocalScript
local plr = game.Players.LocalPlayer

With any player instance, you can get their character with

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

So your code would be...

local plr = game.Players.LocalPlayer
local character = plr.Character
function KeyPress(input, gameProcessed)
    if input.KeyCode == Enum.KeyCode.T then
        char.Head.Size = --put size here or somethin
    end
end

game:GetService("UserInputService").InputBegan:Connect(KeyPress)

Unless you wanted to use workspace...

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

Hope this helps!

This discussion is preserved as it was. New answers, comments, and votes are closed.