How do I define a localplayer in the workspace?

I’m trying to access the localplayer in the workspace by doing:

local LPlayer = game.Workspace.Localplayer

But that doesn’t seem to work. This is what im trying to do:

LPlayer:WaitForChild("Arm1"):Destroy()
LPlayer:WaitForChild("Arm2"):Destroy()
LPlayer:WaitForChild("Chest"):Destroy()

You cant define a local player in workspace

you mean the character?
a character is a child of workspace
a player is a child of game.Players


game.Players.LocalPlayer can only be done in a localscript

How would I do it then because I know no other way.

can you explain further what your trying to do?

Im trying to access image

I have a UI that will soon let you put on a jacket. when they are equipted they look like this in the player model image
Arm1, Arm2, Chest, I have added a button to the ui to remove all. Thats why

is a LocalScript you can try

game.Players.LocalPlayer.Character

But isnt the player model in the workspace and not players?

a local script wont work because it will only show for the client and everyone else in the server wont see the shirt, a server script is required

Its in a server script

remoteEvent.OnServerEvent:Connect(function(player, val)
	if val == "Event_Remove_Jackets" then
		print("Staff_UI_Priority Event fired.")
		print("Staff_UI_Priority Event: ", val)
		LPlayer:WaitForChild("Arm1"):Destroy()
		LPlayer:WaitForChild("Arm2"):Destroy()
		LPlayer:WaitForChild("Chest"):Destroy()
	end
end)

No idea if the destroy part is correct.

yes a character is a model in the workspace
a player instance has a property that reference the character. that is named character

1 Like

can you show more parts of the script?

Would you like to see the whole UI handler?

just the part “LPlayer” (char limit)

I believe you do:

local player = game:GetService(“Players”)

local character = player.Character

That’ll error, you can’t get a character model returned from the entire service

I removed all the over events from the message.

--// Staff UI Remote Event \\--
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("Staff_UI_Priority")

--// Game Stuff \\--
local Character = game.Players.LocalPlayer.Character


--// Jackets \\--
remoteEvent.OnServerEvent:Connect(function(player, val)
	if val == "Event_Remove_Jackets" then
		print("Staff_UI_Priority Event fired.")
		print("Staff_UI_Priority Event: ", val)
		Character:WaitForChild("Arm1"):Destroy()
		Character:WaitForChild("Arm2"):Destroy()
		Character:WaitForChild("Chest"):Destroy()
	end
end)

you need a for-loop to make this work

You cannot get LocalPlayer on a server script, however you can use the player argument that’s in the first parameter of the OnServerEvent, it returns the player that fired the event, so instead of using Character use player.Character

1 Like