Hey there!
How would I go about scripting a part that changes a player’s skin color when they touch it?
Normally, you shouldn’t be asking for code for free. You should at least attempt to make your own so we know you’ve put in effort.
You can accomplish your goal by using a .Touched event along with other things thats explained in the script. Hopefully this helps and there may be typos.
-- Variables --
local PS = game:GetService("Players");
local TouchBrick = script.Parent; -- The brick they have to touch
local ColorToSet = Color3.fromRGB(0, 255, 255); -- Color you want the players character to change to
-- Touch Connection --
TouchBrick.Touched:Connect(function(Hit) -- Use a .Touched to see when the player touches the part
local Player = PS:GetPlayerFromCharacter(Hit.Parent); -- A function that returns the player of the given model (returns nil if not a player)
if Player then -- Check if the Hit objects parent is a player (it will return nil if not)
for _, BodyPart in pairs(Hit.Parent:GetChildren())do -- Loop through all children of the players character
if BodyPart:IsA("BasePart") then -- Make sure its a part!
BodyPart.Color = ColorToSet; -- Set the body part color to our ColorToSet variable
end;
end;
end;
end);
How its setup if you’re wondering:
1 Like
Use the touch event: BasePart | Documentation - Roblox Creator Hub
Then, connect it to the character changing script: How can I change the character to another character?
Oh, sorry. I forgot to add in the code I’ve tried.
local touched = {}
function find(player)
for _, v in pairs(touched) do
if v == player then
return true
end
end
end
script.Parent.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player and not find(player) then
table.insert(touched, player)
player.["Body Color"].HeadColor = Color3.fromRGB(0, 255, 38)
end
end)
Thanks for reminding me!