How to combine 2 scripts into 1?

hello everyone, I have 2 scripts and I would like to connect them so that it turns out together, well, I create training zones when you stand on a part, a boost is added to you and I don’t want to write a training zone script separately on each part.

local player = game.Players:GetPlayerFromCharacter(character)
local gui = player.PlayerGui.SafeZoneGui

local root = character.HumanoidRootPart
local radius = 20

local strength = player.Strength
local psp = player.Psp
local endurance = player.Endurance

local sMulti = player.ZoneMulti
local pMulti = player.pZoneMulti
local eMulti = player.eZoneMulti

-- ZONE ROOTS
local rockRoot    = game.Workspace.RockZone.Rock
local pspRoot     = game.Workspace.TestPsychicZone.Rock
local areRoot     = game.Workspace.Pea.Are
local treadmillRoot = game.Workspace.TreadmillZone.treadmill
local bicepRoot   = game.Workspace.BicepZone.Bicep
local sandboxRoot = game.Workspace.sandboxZone.sandbox
local qualityRoot = game.Workspace.qualityZone.quality
local elektroRoot = game.Workspace.ElektroZone.elektro
local treeRoot    = game.Workspace.TreeZone.tree
local treadmill2Root = game.Workspace.TreadmillZone2.treadmill2
local treadmill3Root = game.Workspace.TreadmillZone3.treadmill3
local bicepRoot2   = game.Workspace.BicepZone2.Bicep2
local bicepRoot3   = game.Workspace.BicepZone3.Bicep3
local libraryRoot   = game.Workspace.LibraryZone.library
local libraryRoot2   = game.Workspace.LibraryZone2.library2
local libraryRoot3   = game.Workspace.LibraryZone3.library3
local lavaRoot   = game.Workspace.LavaZone.Lava
local bridgeRoot = game.Workspace.BridgeZone.bridge
local policeRoot1 = game.Workspace.PoliceZone.Police
local policeRoot2 = game.Workspace.TrainPoliceZone.Police
local policeRoot3 = game.Workspace.PoliceZone2.police
local PyramidRoot = game.Workspace.PyramidZone.Rock
local PyramidRoot2 = game.Workspace.PyramidZone2.Test
local PyramidRoot3 = game.Workspace.PyramidZone3.Rock
local cactusRoot2 = game.Workspace.CactusZone2.Test
local cactusRoot = game.Workspace.CactusZone.cactus
local pyramidRoot3 = game.Workspace.PyramidZone3.Rock
local pyramidRoot4 = game.Workspace.PyramidZone4.Lava
local snowRoot = game.Workspace.SnowZone1.Rock
local snowRoot2 = game.Workspace.SnowZone2.Rock
local snowRoot3 = game.Workspace.SnowZone3.cactus
local snowRoot4 = game.Workspace.SnowZone4.Rock
local snowRoot5 = game.Workspace.SnowZone5.quality
local snowRoot6 = game.Workspace.SnowZone6.quality
local volcanoRoot = game.Workspace.VolcanoZone.treadmill3
local volcanoRoot2 = game.Workspace.VolcanoZone2.Are
local volcanoRoot3 = game.Workspace.VolcanoZone3.Rock
local volcanoRoot4 = game.Workspace.VolcanoZone4.Bicep3
local volcanoRoot5 = game.Workspace.VolcanoZone5.treadmill3
local volcanoRoot6 = game.Workspace.VolcanoZone6.Rock
local woltRoot = game.Workspace.woltZone.Lava
local woltRoot2 = game.Workspace.woltZone2.Rock
local woltRoot3 = game.Workspace.woltZone3.Rock
local woltRoot4 = game.Workspace.woltZone4.Lava
local woltRoot5 = game.Workspace.WoltZone5.Rock
local woltRoot6 = game.Workspace.WoltZone6.Rock

while wait(0.0000000001) do
	-- Reset multipliers
	sMulti.Value = 1
	pMulti.Value = 1
	eMulti.Value = 1

	-- Calculate distances
	local rockDistance     = (root.Position - rockRoot.Position).Magnitude
	local pspDistance      = (root.Position - pspRoot.Position).Magnitude
	local areDistance      = (root.Position - areRoot.Position).Magnitude
	local treadmillDistance = (root.Position - treadmillRoot.Position).Magnitude
	local BicepDistance = (root.Position - bicepRoot.Position).Magnitude
	local sandboxDistance = (root.Position - sandboxRoot.Position).Magnitude
	local qualityDistance = (root.Position - qualityRoot.Position).Magnitude
	local elektroDistance = (root.Position - elektroRoot.Position).Magnitude
	local treeDistance = (root.Position - treeRoot.Position).Magnitude
	local treadmill2Distance = (root.Position - treadmill2Root.Position).Magnitude
	local treadmill3Distance = (root.Position - treadmill3Root.Position).Magnitude
	local BicepDistance2 = (root.Position - bicepRoot2.Position).Magnitude
	local BicepDistance3 = (root.Position - bicepRoot3.Position).Magnitude
	local libraryDistance = (root.Position - libraryRoot.Position).Magnitude
	local libraryDistance2 = (root.Position - libraryRoot2.Position).Magnitude
	local libraryDistance3 = (root.Position - libraryRoot3.Position).Magnitude
	local lavaDistance = (root.Position - lavaRoot.Position).Magnitude
	local bridgeDistance = (root.Position - bridgeRoot.Position).Magnitude
	local policeDistance1 = (root.Position - policeRoot1.Position).Magnitude
	local PoliceDistance2 = (root.Position - policeRoot2.Position).Magnitude
	local PoliceDistance3 = (root.Position - policeRoot3.Position).Magnitude
	local PyramidDistance = (root.Position - PyramidRoot.Position).Magnitude
	local PyramidDistance2 = (root.Position - PyramidRoot2.Position).Magnitude
	local CactusDistance = (root.Position - cactusRoot.Position).Magnitude
	local CactusDistance2 = (root.Position - cactusRoot2.Position).Magnitude
	local PyramidDistance3 = (root.Position - pyramidRoot3.Position).Magnitude
	local PyramidDistance4 = (root.Position - pyramidRoot4.Position).Magnitude
	local snowDistance = (root.Position - snowRoot.Position).Magnitude
	local snowDistance2 = (root.Position - snowRoot2.Position).Magnitude
	local snowDistance3 = (root.Position - snowRoot3.Position).Magnitude
	local snowDistance4 = (root.Position - snowRoot4.Position).Magnitude
	local snowDistance5 = (root.Position - snowRoot5.Position).Magnitude
	local snowDistance6 = (root.Position - snowRoot6.Position).Magnitude
	local volcanoDistance = (root.Position - volcanoRoot.Position).Magnitude
	local volcanoDistance2 = (root.Position - volcanoRoot2.Position).Magnitude
	local volcanoDistance3 = (root.Position - volcanoRoot3.Position).Magnitude
	local volcanoDistance4 = (root.Position - volcanoRoot4.Position).Magnitude
	local volcanoDistance5 = (root.Position - volcanoRoot5.Position).Magnitude
	local volcanoDistance6 = (root.Position - volcanoRoot6.Position).Magnitude
	local woltDistance = (root.Position - woltRoot.Position).Magnitude
	local woltDistance2 = (root.Position - woltRoot2.Position).Magnitude
	local woltDistance3 = (root.Position - woltRoot3.Position).Magnitude
	local woltDistance4 = (root.Position - woltRoot4.Position).Magnitude
	local woltDistance5 = (root.Position - woltRoot5.Position).Magnitude
	local woltDistance6 = (root.Position - woltRoot6.Position).Magnitude
	

	-- Apply multipliers based on location
	if rockDistance <= radius and strength.Value >= 100 then -- 100
		sMulti.Value = 5
	end
	
	if lavaDistance <= radius and endurance.Value >= 100 then -- 100
		eMulti.Value = 5
	end
	
	if bridgeDistance <= radius and psp.Value >= 100 then -- 100 psp
		pMulti.Value = 5
	end

	if pspDistance <= radius and psp.Value >= 100000000000 then -- 100b psp
		pMulti.Value = 125000
	end
	
	if areDistance <= radius and strength.Value >= 5000 then -- 5K
		sMulti.Value = 20
	end
	
	if treadmillDistance <= radius and endurance.Value >= 100000 then -- 100k
		eMulti.Value = 100
	end
	
	if BicepDistance <= radius and strength.Value >= 100000 then -- 100k
		sMulti.Value = 100
	end
	
	if sandboxDistance <= radius and psp.Value >= 5000 then -- 5k
		pMulti.Value = 20
	end
	
	if qualityDistance <= radius and endurance.Value >= 5000 then -- 5k
		eMulti.Value = 20
	end
	
	if elektroDistance <= radius and endurance.Value >= 100000000000 then -- 100b
		eMulti.Value = 125000
	end
	
	if treeDistance <= radius and psp.Value >= 1000000000 then -- 1B
		pMulti.Value = 25000
	end
	
	if treadmill2Distance <= radius and endurance.Value >= 5000000 then -- 5m
		eMulti.Value = 1000
	end
	
	if treadmill3Distance <= radius and endurance.Value >= 1000000000 then -- 1B
		eMulti.Value = 25000
	end
	
	if BicepDistance2 <= radius and strength.Value >= 5000000 then -- 5m
		sMulti.Value = 1000
	end
	
	if BicepDistance3 <= radius and strength.Value >= 1000000000 then -- 1B 
		sMulti.Value = 25000
	end
	
	if libraryDistance <= radius and psp.Value >= 5000 then -- 5k psp
		pMulti.Value = 20
	end
	
	if libraryDistance2 <= radius and psp.Value >= 100000 then -- 100k psp
		pMulti.Value = 100
	end
	
	if libraryDistance3 <= radius and psp.Value >= 5000000 then -- 5m psp
		pMulti.Value = 1000
	end
	
	if policeDistance1 <= radius and psp.Value >= 5000000000000 then -- 5t psp
		pMulti.Value = 1000000
	end
	
	if PoliceDistance2 <= radius and strength.Value >= 5000000000000 then -- 5t
		sMulti.Value = 1000000
	end
	
	if PoliceDistance3 <= radius and endurance.Value >= 5000000000000 then -- 5t
		eMulti.Value = 1000000
	end
	
	if PyramidDistance <= radius and psp.Value >= 5000000000000000 then -- 5Qa psp
		pMulti.Value = 15000000
	end
	
	if PyramidDistance2 <= radius and strength.Value >= 5000000000000000 then -- 5Qa
		sMulti.Value = 15000000
	end
	
	if PyramidDistance3 <= radius and psp.Value >= 5000000000000000000 then -- 5Qi
		pMulti.Value = 100000000
	end
	
	if PyramidDistance4 <= radius and endurance.Value >= 5000000000000000000 then -- 5Qi
		eMulti.Value = 100000000
	end
	
	if CactusDistance2 <= radius and endurance.Value >= 5000000000000000000 then -- 5qi
		eMulti.Value = 100000000
	end
	
	if CactusDistance <= radius and strength.Value >= 5000000000000000000 then -- 5Qi
		sMulti.Value = 100000000
	end
	
	if CactusDistance2 <= radius and endurance.Value >= 5000000000000000000 then -- 5qi
		eMulti.Value = 100000000
	end
	
	if PyramidDistance4 <= radius and psp.Value >= 5000000000000000 then -- 5Qd psp
		pMulti.Value = 15000000
	end
	
	if snowDistance <= radius and psp.Value >= 1000000000000000000000 then -- 1sx psp
		pMulti.Value = 2500000000
	end
	
	if snowDistance2 <= radius and psp.Value >= 7000000000000000000000000 then -- 7sp psp
		pMulti.Value = 75000000000
	end
	
	if snowDistance3 <= radius and strength.Value >= 1000000000000000000000 then -- 1sx
		sMulti.Value = 2500000000
	end
	
	if snowDistance4 <= radius and strength.Value >= 7000000000000000000000000 then -- 7sp
		sMulti.Value = 75000000000
	end
	
	if snowDistance5 <= radius and endurance.Value >= 1000000000000000000000 then -- 1sx
		eMulti.Value = 2500000000
	end
	
	if snowDistance6 <= radius and endurance.Value >= 7000000000000000000000000 then -- 7sp
		eMulti.Value = 75000000000
	end
	
	if volcanoDistance <= radius and endurance.Value >= 3000000000000000000000000000 then -- 3oc
		eMulti.Value = 1000000000000
	end
	
	if volcanoDistance2 <= radius and strength.Value >= 3000000000000000000000000000 then -- 3oc
		sMulti.Value = 1000000000000
	end
	
	if volcanoDistance3 <= radius and psp.Value >= 3000000000000000000000000000 then -- 3oc psp
		pMulti.Value = 1000000000000
	end
	
	if volcanoDistance4 <= radius and strength.Value >= 5000000000000000000000000000 then -- 5n
		sMulti.Value = 1000000000000000
	end
	
	if volcanoDistance5 <= radius and endurance.Value >= 5000000000000000000000000000 then -- 5n
		eMulti.Value = 1000000000000000
	end
	
	if volcanoDistance6 <= radius and psp.Value >= 5000000000000000000000000000 then -- 5N psp
		pMulti.Value = 1000000000000000
	end
	
	if woltDistance <= radius and endurance.Value >= 3000000000000000000000000000000 then -- 3Dc 
		eMulti.Value = 250000000000000000
	end
	
	if woltDistance2 <= radius and psp.Value >= 3000000000000000000000000000000 then -- 3Dc psp
		pMulti.Value = 250000000000000000
	end
	
	
	if woltDistance3 <= radius and psp.Value >= 100000000000000000000000000000000000 then -- 1Dd psp
		pMulti.Value = 50000000000000000000
	end
	
	if woltDistance4 <= radius and endurance.Value >= 100000000000000000000000000000000000 then -- 3Dc 
		eMulti.Value = 50000000000000000000
	end
	
	if woltDistance5 <= radius and strength.Value >= 3000000000000000000000000000000 then -- 3Dc 
		sMulti.Value = 250000000000000000
	end
	
	
	if woltDistance6 <= radius and strength.Value >= 100000000000000000000000000000000000 then -- 3Dc 
		sMulti.Value = 50000000000000000000
	end
	
end
2 Likes

and here is the following script that I would like to connect


local playersInside = {}

script.Parent.Touched:Connect(function(hit)
	if hit.Name ~= "HumanoidRootPart" then return end

	local player = Player:GetPlayerFromCharacter(hit.Parent)
	if not player then return end

	local strength = player:FindFirstChild("Strength")
	if not strength or strength.Value < 100 then return end

	table.insert(playersInside, player)
	while table.find(playersInside, player) do
		wait(2)
		if not table.find(playersInside, player) then return end
		local endurance = player:FindFirstChild("Endurance")
		if endurance then
			endurance.Value = endurance.Value + 1 
		end
	end
end)

script.Parent.TouchEnded:Connect(function(hit)
	if hit.Name ~= "HumanoidRootPart" then return end

	local player = Player:GetPlayerFromCharacter(hit.Parent)
	if not player then return end

	local playerIndex = table.find(playersInside, player)
	if playerIndex then
		table.remove(playersInside, playerIndex)
	end
end)

I want to connect them, but I do not know how to do it without bugs

I want the multiplier to be eMulti and not the other one

first of all dont do while wait() do. Do this instead

While True do
     task.wait(0)
end

One thing use for i,v in pairs. It basically loops through the children in a parent. I would reccoment putting all of those in a folder and organizing a bit.

And third thing if you wanna put everything into one script do it before the while loop. Unless you use task.spawn. And if its glitching and stuff you can just disable the event by using example:

local event = script.Parent.TouchEnded:Connect(function(hit)
if hit.Name ~= “HumanoidRootPart” then return end

local player = Player:GetPlayerFromCharacter(hit.Parent)
if not player then return end

local playerIndex = table.find(playersInside, player)
if playerIndex then
	table.remove(playersInside, playerIndex)
end

end)
and you can just disable the event with the :disconnect() function like this:

event:Disconnect()
1 Like

I get it, thank you, but how do I connect these 2 scripts into 1? which at the beginning of the theme in the script I attached

for start i wanna know where are those 2 scripts located. And second thing you want both scripts to be just one or no?

if not you can connect them with bilndable events and remote events (or bilndable functions and remote functions)

1 script that is large is in the starter player and in the StrarerCharacterscript

But the second small script in the part

I’d like to combine a small script into a large script

you mean turn it into a one single script?

and that the multiplier should be eMulti

yes that’s exactly what I’d like to do

Hmmm. Maybe put the script in a player.CharacterAdded()

Look, I will insert a small script into a large script, I will have an error anyway, but I don’t need it

Mangle I’ll put a little script in a big I’ll have a mistake

Sorry for the translator, I didn’t quite understand what you wanted to say

I would suggest using bilndable events or remote events. You know how they function right?

Not exactly, but yes I know How they work