Script Can't Access Character

This is probably obvious to most people but I can’t figure out how to access the player character in this script,
local scaleFactor = 0.5
script.Parent.MouseButton1Down:connect(function(Player)
Player.Character.Humanoid.BodyDepthScale.Value = Player.Character.Humanoid.BodyDepthScale.Value * scaleFactor
Player.Character.Humanoid.BodyDepthScale.Value = Player.Character.Humanoid.BodyDepthScale.Value * scaleFactor

end)

and here’s the error message:
Players.TheEpicWoomy.PlayerGui.ScreenGui.Frame.TextButton.Script:3: attempted to index number with ‘Character’

To my knowledge you can’t get the player from a MouseButton1Down function. Since it’s a local script, just make a separate variable calling game.Players.LocalPlayer and one for the character, which you can just do Player.Character.

would’ve done that but, it’s not a local script.
I’d assume you wouldn’t be able to resize a player for everyone in a local script.

I wouldn’t recommend using Server Scripts for UI’s as they are client based and should be handled by the client. I would use a remote event and send the data to the event, and change their size with the argument.

2 Likes

I would still have to get player.character in a script fired from the remote event though, how would I go about that (script obviously no longer using a MouseButton1Down function)
current script
local scaleFactor = 0.5
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function()
Player.Character.Humanoid.BodyDepthScale.Value = Player.Character.Humanoid.BodyDepthScale.Value * scaleFactor
Player.Character.Humanoid.BodyDepthScale.Value = Player.Character.Humanoid.BodyDepthScale.Value * scaleFactor
end)

MouseButton1Down passes the X and Y positions of input, not the player. If you were unsure of what parameters the function took, there’s always documentation on the Developer Hub.

In the first place, you can’t (or shouldn’t be) changing this from the client-side anyway. If you’re using a regular script in a Gui, then that’s also improper and should be changed to a LocalScript which fires a remote to the server requesting to change the scaling of the character.

Regarding your recent remote attempt: the player who fired the remote is passed implicitly as the first argument, so just adding Player to the parenthesis will fix your function.

1 Like

Make sure to add it to the front of the parenthesis though.