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

How do I change the appearance of the local player with the mouse.Target?

So I was trying to make you copy the same appearance of the player the mouse is on when you press Q.

IN ServerScriptService

 local ReplicatedStorage = game:GetService("ReplicatedStorage") 
local Trans = ReplicatedStorage.Quinl.Transformar

function transformar(plr, plr2)
plr.CharacterAppearanceId = plr2.UserId
plr:LoadCharacter()
end

Trans.OnServerEvent:Connect(transformar)

Local Script

plr = game.Players.LocalPlayer
Rep = game:GetService("ReplicatedStorage")
Trans = Rep.Quinl.Transformar
local UIS = game:GetService("UserInputService")
mouse = plr:GetMouse()

UIS.InputBegan:Connect(function(inputObject)
   if(inputObject.KeyCode==Enum.KeyCode.Q)then
	if mouse and mouse.Target and mouse.Target.Parent and mouse.Target.Parent:IsA("Model") then
local plr2 = game.Players:GetPlayerFromCharacter(mouse.Target.Parent)
    if plr2 then
Trans:FireServer(plr2)
		    end
	    end
    end
end)

No matter what I try the character does not change.

Any help? Haven#2692

2 comments

1

psst KeyDown is deprecated use UserInputService, also use GetService instead of indexing DataModel

0

^

1 answer

✓ Accepted answer

UserInputService

Use this service to see what buttons the LocalPlayer pressed. This is the recommended service to use because it has more options and receives updates.

HumanoidDescription

https://developer.roblox.com/articles/humanoiddescription-system Roblox released this a couple weeks ago. If you want to fully copy a person, this is perfect for just that! All you have to do is use Humanoid:ApplyDescription(HumanoidDescription) to make that Humanoid copy its outfit.

Note: Doesn't work with NPCs last time I checked.

Applying

First, we need to use UserInputService to find out what the LocalPlayer pressed. We then need to decide if they pressed a certain key, it this case, it is 'Q'. To find when an input is pressed, we use InputBegan.

Local Script:

local UserInputService = game:GetService('UserInputService')

UserInputService.InputBegan:Connect(function(Input, GPE)
    --GPE is true when LocalPlayer is using a GUI
    --We wouldn't want the player typing 'q' in the chat
    --and accidentally change outfits.
    
    if (not GPE) then
    
	    local KeyCode = Input.KeyCode
	    --convert input to a KeyCode

		if (KeyCode == Enum.KeyCode.Q) then
			RemoteEvent:FireServer()
		end
		
    end
end)

Now all you need to do is have the server apply the description based on what the client sends.

I suggest you check the wiki page for HumanoidDescription. It has how you can apply these to other players and gets into more detail. It'll get you towards what you are trying to achieve better than I can explain.

Good luck!

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