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

Combining 2 tool scripts?

So here I have two tool scripts that give a item when clicked. One gives Drink1, another one gives, Raw Hamburger. How would I combine the two scripts to give one item and have the two parts still present?

Script 1

script.Parent.ClickDetector.MouseClick:connect(function(player)
local cup = script.Parent.Parent:FindFirstChild("Cup")
	cup.CFrame = CFrame.new (cup.CFrame.X,cup.CFrame.Y-0.0,cup.CFrame.Z)
	local tool = script.Tool:clone()
	local handle = script.Parent.Parent.Cup:clone()
	tool.Parent = player.Backpack
	handle.Parent = tool
	handle.Name = "Handle"
	tool.ToolTip = script.Parent.Parent.Name
	tool.Name = "Raw Hamburger"
	for _,two in pairs(tool:GetChildren()) do
		if two:IsA ("LocalScript") then
			two.Disabled = false	
			wait()		
		end
	end
	for i = 1,8 do
		cup.CFrame = CFrame.new(cup.CFrame.X,cup.CFrame.Y+0.0,cup.CFrame.Z)
		wait()
	
	end
end)

Script 2

script.Parent.ClickDetector.MouseClick:connect(function(player)
local Drink1 = script.Parent.Parent:FindFirstChild("Drink1")
	Drink1.CFrame = CFrame.new (Drink1.CFrame.X,Drink1.CFrame.Y-0.0,Drink1.CFrame.Z)
	local tool = script.Tool:clone()
	local handle = script.Parent.Parent.Drink1:clone()
	tool.Parent = player.Backpack
	handle.Parent = tool
	handle.Name = "Handle"
	tool.ToolTip = script.Parent.Parent.Name
	tool.Name = "Drink1"
	for _,two in pairs(tool:GetChildren()) do
		if two:IsA ("LocalScript") then
			two.Disabled = false	
			wait()		
		end
	end
	for i = 1,8 do
		Drink1.CFrame = CFrame.new(Drink1.CFrame.X,Drink1.CFrame.Y+0.0,Drink1.CFrame.Z)
		wait()
	end
end)

1 answer

✓ Accepted answer

This seems like a simple matter of defining your variables

It's fine to have more than one script, but if you want two, I have no room to argue.

This is quite easy,

First, define the two ClickDetectors,

--Regular script in ServerScriptService, or anywhere in Workspace
local ClickDetector1 = game.Workspace:WaitForChild("Part1"):WaitForChild("ClickDetector")
local ClickDetector2 = game.Workspace:WaitForChild("Part2"):WaitForChild("ClickDetector")

Great, now we just have to throw in your scripts, but substitute the script.Parent.ClickDetector with our new variables,

--Regular script in ServerScriptService, or anywhere in Workspace
local ClickDetector1 = game.Workspace:WaitForChild("Part1"):WaitForChild("ClickDetector")
local ClickDetector2 = game.Workspace:WaitForChild("Part2"):WaitForChild("ClickDetector")

ClickDetector1.MouseClick:connect(function(player)
local cup = script.Parent.Parent:FindFirstChild("Cup")
    cup.CFrame = CFrame.new (cup.CFrame.X,cup.CFrame.Y-0.0,cup.CFrame.Z)
    local tool = script.Tool:clone()
    local handle = script.Parent.Parent.Cup:clone()
    tool.Parent = player.Backpack
    handle.Parent = tool
    handle.Name = "Handle"
    tool.ToolTip = script.Parent.Parent.Name
    tool.Name = "Raw Hamburger"
    for _,two in pairs(tool:GetChildren()) do
        if two:IsA ("LocalScript") then
            two.Disabled = false    
            wait()      
        end
    end
    for i = 1,8 do
        cup.CFrame = CFrame.new(cup.CFrame.X,cup.CFrame.Y+0.0,cup.CFrame.Z)
        wait()
    end
end)

ClickDetector2.MouseClick:connect(function(player)
local Drink1 = script.Parent.Parent:FindFirstChild("Drink1")
    Drink1.CFrame = CFrame.new (Drink1.CFrame.X,Drink1.CFrame.Y-0.0,Drink1.CFrame.Z)
    local tool = script.Tool:clone()
    local handle = script.Parent.Parent.Drink1:clone()
    tool.Parent = player.Backpack
    handle.Parent = tool
    handle.Name = "Handle"
    tool.ToolTip = script.Parent.Parent.Name
    tool.Name = "Drink1"
    for _,two in pairs(tool:GetChildren()) do
        if two:IsA ("LocalScript") then
            two.Disabled = false    
            wait()      
        end
    end
    for i = 1,8 do
        Drink1.CFrame = CFrame.new(Drink1.CFrame.X,Drink1.CFrame.Y+0.0,Drink1.CFrame.Z)
        wait()
    end
end)

Now, that should work. However, I'm not 100% if this was what you wanted.

I hope I helped!

Good Luck!

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