Please don't make requests on Scripting Helpers. Instead, attempt to do this yourself, and come back if you are having issues with your code. Your question should usually contain code. I'm feeling nice though, so I'll explain how this works step-by-step:
First we'll have our TextButton inside a ScreenGui, which is in the StarterGui. In the button, we'll make a LocalScript. To put clothing on the player's character, we'll have to use a RemoteEvent to communicate with the server, because it needs to perform the action. This will be the local script's content:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remote = ReplicatedStorage:WaitForChild("RemoteEvent")
local button = script.Parent
button.MouseButton1Click:Connect(function()
Remote:FireServer()
end)
This is great. Everytime the button is clicked, a remote event will be fired. Now, all we have to do is set up the server's action in response to the remote. Put this ServerScript in the ServerScriptService:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remote = Instance.new("RemoteEvent")
Remote.Parent = ReplicatedStorage
local ShirtId = "rbxassetid://YourShirtIdHere"
local PantsId = "rbxassetid://YourPantsIdHere"
Remote.OnServerEvent:Connect(function(player)
local Shirt = player.Character:FindFirstChildOfClass("Shirt")
local Pants = player.Character:FindFirstChildOfClass("Pants")
if Shirt then
Shirt.ShirtTemplate = ShirtId
else
Shirt = Instance.new("Shirt")
Shirt.ShirtTemplate = ShirtId
Shirt.Parent = player.Character
end
if Pants then
Pants.PantTemplate = PantsId
else
Pants = Instance.new("Pants")
Pants.PantsTemplate = PantsId
Pants.Parent = player.Character
end
end)
In this script, we listen for the remote event to be fired. If it is, we scan the player's character for shirt and pants. If they exist, we simply edit their respective templates. Otherwise, we make new ones and do the same.
##Resources:
Remote Events
##Accept and upvote if this helps!
1 comment
ServerScriptService*