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 4 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

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?

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

1 answer

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

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!

Ad

Answer this question