So, im trying to make a button that when is clicked and a value is setted to the kit name u selected, the players of that specific team would have the clothes of the kit you’ve selected.
the problem is, i tried doing it by firing a remote event when the button is clicked but it doesnt work, i tried doing it by just using the local script and it works but since the local script is client sided only you can see the player that have clothes meanwhile others can’t.
and now im trying doing on a serverscrpt but it still wont work.
here how i made it
serverscript inside the button:
script.Parent.MouseButton1Click:Connect(function()
local value = script.Parent.Parent.Parent.TeamKit.AwayTeam.AwayValueKit
for i,v in pairs(game.Teams.Away:GetPlayers()) do
if value.Value == "Raimon Kit" then
v.Character:FindFirstChild("Pants").PantsTemplate = --asset id
v.Character:FindFirstChild("Shirt").ShirtTemplate = --asset id
elseif value.Value == "Royal Kit" then
v.Character:FindFirstChild("Pants").PantsTemplate = --asset id
v.Character:FindFirstChild("Shirt").ShirtTemplate = --asset id
--elseif value.Value == "Occult Kit" then, and so on with the kits
end
end
end)
You have to use a remote event or remote function, code it again (or go back if you still have it) and keep me updated if it doesn’t work again.
EDIT: Also don’t use elseifs like that, it can always be replaced by a dictionary/table for better readability, here’s how you would use a dictionary instead of elseifs for your case:
local kits = {
["Raimon Kit"] = {
ShirtId = "rbxassetid://1",
PantsId = "rbxassetid://2",
},
["Royal Kit"] = {
ShirtId = "rbxassetid://3",
PantsId = "rbxassetid://4",
}
}
local function equipKit(char, kitName)
local kitInfo = kits[kitName]
if not kitInfo then --no kit under that name
warn("No kit found")
return --return to stop the function
end
local currentShirt = char:FindFirstChildWhichIsA("Shirt") --let's instead check for the class name just to be sure
local currentPants = char:FindFirstChildWhichIsA("Pants")
if not currentShirt then --does the character not have a shirt equipped?
currentShirt = Instance.new("Shirt") --lets give him a shirt instance then
currentShirt.Parent = char
end
if not currentPants then --does the character not have pants equipped?
currentPants = Instance.new("Pants") --let's give him a pants instance then
currentPants.Parent = char
end
currentShirt.ShirtTemplate = kitInfo.ShirtId
currentShirt.PantsTemplate = kitInfo.PantsId
end
So far i did the function that u did and added this
remote.OnServerEvent:Connect(function(Player, KitName)
local kit = kits[KitName]
equipKit(Player.character, kit)
end)
And then in the local script inside the button:
local remote = game:GetService("Replicated Storage"):WaitForChild("Events").Kit
script.Parent.MouseButton1Click:Connect(function()
local value = script.Parent.Parent.Parent.TeamKit.AwayKit.KitValue
for i, v in pairs(Players:GetPlayers()) do
local char = v.Character or v.CharacterAdded:Wait()
if v.Team.Name == "Away" then
if value.Value == "Raimon Kit" then
remote:FireServer(char, "Raimon Kit")
elseif value.Value == "Royal Kit" then
remote:FireServer(char, "Royal Kit")
----
end
end
end
end)