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

How to select LocalPlayer's Character with LocalScript?

I tried to use LocalPlayer with LocalScript (Because LocalScript is a client side(Also is LocalPlayer)) Here is my code:

local player = game.Players.LocalPlayer
local character = player.Character
local GUIButton = game.StarterGUI.ScreenGui.TextButton

GUIButton.Mouse1ButtonClick:Connect(function()
character.Humanoid.WalkSpeed = character.Humanoid.WalkSpeed + 7
end)

3 comments

0

I meant MouseButton1Click; Dont mind that typo

0

And, what's your Problem there?

0

That the Local Player's Character Property is not working

2 answers

✓ Accepted answer

You need to get the player's character by using script.Parents. You need to type them until it points at nothing. When you can't type anything else besides another parent, then minus one parent, and it will show a few options. Ignore those options, and let's get to the script.

local player = script.Parent.Parent.Parent.Parent.Parent
local char = player.Character
local GUIButton = game.StarterGUI.ScreenGui.TextButton

GUIButton.MouseButton1Click:Connect(function()
char.Humanoid.WalkSpeed = char.Humanoid.WalkSpeed + 7
end)

Put this script into StarterCharacterScripts so it will run after the character is added.

You can also change player.Character to

player.Character or player.CharacterAdded:Wait()

to make it work.

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