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

When you click a player, how do you make them wear a shirt?

I made a tool, so when you click on a player, it can give them a shirt. When I click that other player, it gives myself that shirt, not the other player.

Local script

Tool = script.Parent
PMouse = game.Players.LocalPlayer:GetMouse()
Click = true
on = false
Tool.Equipped:connect(function()
	on = true
end)
Tool.Unequipped:connect(function()
	on = false
end)
Tool.Activated:connect(function()
	if PMouse.Target.Parent:FindFirstChild("Humanoid") and on == true or PMouse.Target == nil and on == true then
		local mouseHitPlr = game.Players:GetPlayerFromCharacter(PMouse.Target.Parent)
		game.ReplicatedStorage.EquipShirt:FireServer(mouseHitPlr)
		Click = false
	end
end)

Server Script

local RS = game:WaitForChild("ReplicatedStorage")
local event = RS.EquipShirt
local ShirtID = "rbxassetid://676428254"

local function onEquipShirt(player)
	
	local foundShirt = player.Character:FindFirstChild("Shirt")
	if not foundShirt then -- if there is no shirt
		print("No Shirt Found:  "..player.Name)
		local newShirt = Instance.new("Shirt",player.Character)
		newShirt.Name = "Shirt"
	else if foundShirt then -- if there is a shirt
		print("Existing Shirt Found: Shirt ID has changed for "..player.Name)
		player.Character.Shirt:remove()
		local newShirt = Instance.new("Shirt",player.Character)
		newShirt.Name = "Shirt"
	end
	end
	
	player.Character.Shirt.ShirtTemplate = ShirtID
end

event.OnServerEvent:Connect(onEquipShirt)

1 comment

0

Change the ShirtTemplate of the shirt they are wearing.

1 answer

server script:

local RS = game:WaitForChild("ReplicatedStorage")
local event = RS.EquipShirt
local ShirtID = "rbxassetid://676428254"

local function onEquipShirt(player,mousehit--[[mousehit is the player you clicked on and player is always the player that fired the event, aka the local player]])

    local foundShirt = mousehit.Character.:FindFirstChild("Shirt")
    if not foundShirt then -- if there is no shirt
        print("No Shirt Found:  "..mousehit.Character.Name)
        local newShirt = Instance.new("Shirt",mousehit.Character)
        newShirt.Name = "Shirt"
    else if foundShirt then -- if there is a shirt
        print("Existing Shirt Found: Shirt ID has changed for "..mousehit.Character.Name)
        mousehit.Character.Shirt:remove()
        local newShirt = Instance.new("Shirt",mousehit.Character)
        newShirt.Name = "Shirt"
    end
    end

    mousehit.Character.Shirt.ShirtTemplate = ShirtID
end

event.OnServerEvent:Connect(onEquipShirt)

you connected the player who fired it(the local player not the targeted player), what i changed in this is i also connected the player the mouse hit and put the focus on that very player

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