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)
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:
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.