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

Error finding players character with local player?

local Remote = game.ReplicatedStorage.Remotes.GigantificationRemotes.GigantificationFire

  

  

Remote.OnServerEvent:Connect(function(Player,Mouse)

local player = game.Players.LocalPlayer

local character = player.Character

while true do

wait(0.25)

character.Torso.Size = character.Torso.Size + 1,1,1

wait(4) break

end

end)

getting an error at "local character"

2 answers

The server can't use game.Players.LocalPlayer, it's client-only. If you want the character you can simply use the Character property of the Player argument passed as such:

-- If you're sure the character is there
local character = Player.Character

-- If the character might not have been made yet
local character = Player.Character or Player.CharacterAdded:Wait()

Hope this helps you, feel free to ask any questions or point out mistakes and I'll try my best to help :)

2 comments

0

Line 5 should be Player:WaitForChild("Character"). It will actually wait until it exists.

0

No, Character is a property of the Player instance and waiting for a child named "Character" will not work. The way the fifth line works is that if Player.Character is nil, Player.CharacterAdded:Wait() makes the script yield until the CharacterAdded event fires and then returns the character as an instance (as CharacterAdded passes a character argument when fired)

Assuming this script is on the server side, you cannot use game.Players.LocalPlayeron it. Since you already passed a Player parameter, use that instead of LocalPlayer.

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