How to make my player outfit changer script work specifically for only specific players

Hi! So I have made a feature in my game that basically is an outfit changer, that when you walk onto a part it changes your character’s shirt and pants to a different one. The script works perfectly fine but I don’t know how allow this to work for only me for example.

This is my current script:

local player = game.Players.LocalPlayer
local ChangerPart = script.Parent
local OutfitChanger = ChangerPart.Parent
local ShirtTemplate = OutfitChanger.Shirt.ShirtTemplate
local PantsTemplate = OutfitChanger.Pants.PantsTemplate

ChangerPart.Touched:Connect(function(TouchPart)
    if TouchPart and TouchPart.Parent and TouchPart.Parent:FindFirstChild("Humanoid") then
        print("A player is standing on the changer part!")
        local Character = TouchPart.Parent
        Character.Shirt.ShirtTemplate = ShirtTemplate
		Character.Pants.PantsTemplate = PantsTemplate
    end
end)

So just to make it clear, my aim is to make this script work only for a specific player (me) so an edited version of my script that would only work for a specific player (me). I’ve tried many other scripts and trying it myself but never seems to work!

Any help will be much appreciated! Sorry I am very new to Roblox Developing.

Thanks very much! DannyGT7

1 Like

Do an if check to see if :GetPlayerFromCharacter(TouchPart.Parent) and if that player.UserId == to the specific person you want UserId.

2 Likes

Hello, there.
Just to add to DreamWakeStudios reply, here’s what that would look like, if you’re confused:

local player = game.Players.LocalPlayer
local ChangerPart = script.Parent
local OutfitChanger = ChangerPart.Parent
local ShirtTemplate = OutfitChanger.Shirt.ShirtTemplate
local PantsTemplate = OutfitChanger.Pants.PantsTemplate
local playersAllowed = {0000,0000} -- You put their UserId's here, seperated by a comma, for each player, who should be allowed.

ChangerPart.Touched:Connect(function(TouchPart)
    if TouchPart and TouchPart.Parent and TouchPart.Parent:FindFirstChild("Humanoid") then
        local player = game.Players:GetPlayerFromCharacter(TouchPart.Parent)
        if not player then return end
        if table.find(playersAllowed, player.UserId) then
            print("A player is standing on the changer part!")
            local Character = TouchPart.Parent
            Character.Shirt.ShirtTemplate = ShirtTemplate
		    Character.Pants.PantsTemplate = PantsTemplate
        end
    end
end)
2 Likes

This is it in a nutshell! Thank you. Typing code on mobile drives me nuts :smiley:

1 Like

Sorry about the late reply, WiFi went down lol. But anyways thanks so much for the help! It works! Much appreciated mate, thanks a lot for the help! :smiley:

Sorry about the late reply, WiFi went down lol. But anyways thanks so much for the help! It works! Also thanks very much for adding to @DreamWakeStudios reply and helping with the script, was a bit confused at first but now get it! Much appreciated mate, thanks a lot for the help! :smiley:

2 Likes