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

How would I go about combining multiple scripts into a sigular one?

Hi, I have this very basic "face changer" script that you place inside of a block with a decal on it, and when you touch the decal, your face copies the decal onto it. Now I have several of these decal blocks lined up with a script in each one and wanted to create a overarching script that could substitute each script for a single one. How would I go about doing this? I would want the player to touch one of the decals and for that decal to appear on their face. There would be serval decal blocks all next to each other.

Thank you in advance! Any feedback is great!

This is the script/code for one block. I was thinking of maybe giving each block a numbervalue?

// My workspace looks like this:
//Model
//-FaceChanger
//	-Decal
//-FaceChanger
//	-Decal


//Maybe I do like 

//Model
//-FaceChanger1
//	-Decal
//-FaceChanger2
//	-Decal

//If I did that, I would need to change function getDecal() but this is where I get lost

function onTouch(hit)
	if hit.Parent:FindFirstChild("Humanoid") ~= nil then
		local head = hit.Parent:FindFirstChild("Head")
		if head ~= nil then
			local face = head:FindFirstChild("face")
			if face.Texture ~= getDecal().Texture then
				face.Texture = getDecal().Texture
			end
		end
	end
end

function getDecal()
	local decals
	decals = {}
	for i,child in pairs(script.Parent:GetChildren()) do
		if child.className == "Decal" then
			table.insert(decals, child)
		end
	end
	if #decals ~= 0 then
		return decals[math.random(1, #decals)]
	end
	return nil
end
script.Parent.Touched:Connect(onTouch)

2 answers

you can have a script inside of ServerScriptService and do something like this:

never tested it, may have some errors

local decals = game.Workspace:GetDescendants()
for i,v in pairs (decals) do
if v:IsA("Decal") then -- check if the descendant is a decal
	if v.Parent.Name == "FaceChanger" then -- the decal's parent's name
		v.Touched:Connect(function(hit)
			-- clones the texture to the hit.Parent's face, make sure to check if their humanoid is present first
		end)
	end
end
end

3 comments

0

Thank you, and I love the idea of putting it in the ServerScriptService although it didn't work. I appreciate it tho!

0

why didnt it work?

0

Take a look at what I wrote in the comments below, but basically nothing happens if I touch the part with a decal in it. Not sure what I should do

This is what I now have in the serverscriptservice


function getDecal()
local decals = game.Workspace:GetDescendants()

for i,v in pairs (decals) do
if v:IsA("Decal") then -- check if the descendant is a decal
    if v.Parent.Name == "FaceChanger" then -- the decal's parent's name
        v.Touched:Connect(function(hit)
            -- clones the texture to the hit.Parent's face, make sure to check if their humanoid is present first
        end)
    end
end
end
end

function onTouch(hit)
	if hit.Parent:FindFirstChild("Humanoid") ~= nil then
		local head = hit.Parent:FindFirstChild("Head")
		if head ~= nil then
			local face = head:FindFirstChild("face")
			if face.Texture ~= getDecal().Texture then
				face.Texture = getDecal().Texture
			end
		end
	end
end

script.Parent.Touched:Connect(onTouch)


5 comments

0

And that works?

0

No unfortunately not :/

0

dude, you need to put the on touch function below v.Touched, you connected the function to script.Parent which would be ServerScriptService

0

It is below?

0

no it's not... you're not connecting the right functions, i suggest you go watch some tutorials on the basics first

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