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

How can I make this script loop? (i've tried while true do)

So I have something that lets you change colors of a character but I need it to check whether they selected the head or the torso or left arm... but I can't find out how to loop check it (yes I have tried while true do)

--Variables
local h = script.Parent.Parent.Parent.edit_label.Part.Value
local c = script.color.Value
--head

if h == "Head" then
	script.Parent.MouseButton1Click:connect(function()
		game.Players.LocalPlayer.Data.headcolor.Value = script.Parent.Name
		script.Parent.Parent.Parent.Hat.BackgroundColor3 = Color3.fromRGB(c)
	end)
end
--torso
if h == "Torso" then
	script.Parent.MouseButton1Click:connect(function()
		game.Players.LocalPlayer.Data.headcolor.Value = script.Parent.Name
		script.Parent.Parent.Parent.Hat.BackgroundColor3 = Color3.fromRGB(c)
	end)
end
--larm
if h == "Left arm" then
	script.Parent.MouseButton1Click:connect(function()
		game.Players.LocalPlayer.Data.headcolor.Value = script.Parent.Name
		script.Parent.Parent.Parent.Hat.BackgroundColor3 = Color3.fromRGB(c)
	end)
end
--rarm
if h == "Right arm" then
	script.Parent.MouseButton1Click:connect(function()
		game.Players.LocalPlayer.Data.headcolor.Value = script.Parent.Name
		script.Parent.Parent.Parent.Hat.BackgroundColor3 = Color3.fromRGB(c)
	end)
end
--lleg
if h == "Left leg" then
	script.Parent.MouseButton1Click:connect(function()
		game.Players.LocalPlayer.Data.headcolor.Value = script.Parent.Name
		script.Parent.Parent.Parent.Hat.BackgroundColor3 = Color3.fromRGB(c)
	end)
end
--rleg
if h == "Right leg" then
	script.Parent.MouseButton1Click:connect(function()
		game.Players.LocalPlayer.Data.headcolor.Value = script.Parent.Name
		script.Parent.Parent.Parent.Hat.BackgroundColor3 = Color3.fromRGB(c)
	end)
end

1 comment

0

And don't worry about "Part" thinking its actually a Part, it's just a string value I had no name for.

1 answer

This should work

local h = script.Parent.Parent.Parent.edit_label.Part.Value
local c = script.color.Value

script.Parent.MouseButton1Click:connect(function()
while wait(.1) do
---Head
if h == "Head" then
        game.Players.LocalPlayer.Data.headcolor.Value = script.Parent.Name
        script.Parent.Parent.Parent.Hat.BackgroundColor3 = Color3.fromRGB(c)
---Torso
elseif h == "Torso" then
        game.Players.LocalPlayer.Data.headcolor.Value = script.Parent.Name
        script.Parent.Parent.Parent.Hat.BackgroundColor3 = Color3.fromRGB(c)
---Left Arm
elseif h == "Left arm" then
        game.Players.LocalPlayer.Data.headcolor.Value = script.Parent.Name
        script.Parent.Parent.Parent.Hat.BackgroundColor3 = Color3.fromRGB(c)
---Right Arm
elseif h == "Right arm" then
        game.Players.LocalPlayer.Data.headcolor.Value = script.Parent.Name
        script.Parent.Parent.Parent.Hat.BackgroundColor3 = Color3.fromRGB(c)
---Left Leg
elseif h == "Left leg" then
        game.Players.LocalPlayer.Data.headcolor.Value = script.Parent.Name
        script.Parent.Parent.Parent.Hat.BackgroundColor3 = Color3.fromRGB(c)
---Right Leg
elseif h == "Right leg" then
        game.Players.LocalPlayer.Data.headcolor.Value = script.Parent.Name
        script.Parent.Parent.Parent.Hat.BackgroundColor3 = Color3.fromRGB(c)
end
end
end)

3 comments

0

no it doesn't work :/ but thanks.

0

Try changing the variable local h to local h = script.Parent.Parent.Parent["edit_label"].Part.Value

0

well when I pre-set Part to Head it worked, but if it's set to nothing it doesn't

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