How to combine 2 scripts into 1?

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

IT allows for 2 scripts to communicate. I kinda have 2 ideas right now. Maybe use a module script. Module script is kinda a script inserter. If you dont want to have 100000+ scripts to edit every single update, you can make it into a module script and the stuff that are in module script can be put into your script. You can also insert different values just like in functions(). Second thing is using remote events and bilndable events.