You’re going to need a debounce for the first function as well as it’s going to fire multiple times and allow your 1-4 buttons to fire multiple times.
local firstTouched = false
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') then
if not firstTouched then
firstTouched = not firstTouched
-- then just carry on as normal
Roblox detects multiples collisions in a short amount of time so you are going to need whats called a “Debounce” like @7z99 mentioned. In this example firstTouched will be our Debounce variable.
Also, connecting the different Button’s touched events inside the main function will create those connections every time the main function is called running an unecessary if statement (if button1touch == false then)
I would suggest
local firstTouched = false
script.Parent.Touched:Connect(function(hit)
if not firstTouched and hit.Parent:FindFirstChild("Humanoid") then
firstTouched = true
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local Button1 = game.Workspace.Button1
local Button2 = game.Workspace.Button2
local Button3 = game.Workspace.Button3
local Button4 = game.Workspace.Button4
local button1touch = false
local button2touch = false
local button3touch = false
local button4touch = false
local buttonPressed = player.buttonPressed
player.PlayerGui.PressButtonGui.Frame.Visible = true
local con1 --Connection1
con1 = Button1.Touched:Connect(function(Hit)
if Hit.Parent == hit.Parent then--Check if its the same model touching
con1:Disconnect()
Button1.Color = Color3.fromRGB(38, 38, 38)
Button1.Material = "Metal"
buttonPressed.Value = buttonPressed.Value + 1
end
end)
local con2
con2 = Button2.Touched:Connect(function(Hit)
if Hit.Parent == hit.Parent then--Check if its the same model touching
con2:Disconnect()
Button2.Color = Color3.fromRGB(38, 38, 38)
Button2.Material = "Metal"
buttonPressed.Value = buttonPressed.Value + 1
end
end)
local con3
con3 = Button3.Touched:Connect(function(Hit)
if Hit.Parent == hit.Parent then--Check if its the same model touching
con3:Disconnect()
Button3.Color = Color3.fromRGB(38, 38, 38)
Button3.Material = "Metal"
buttonPressed.Value = buttonPressed.Value + 1
end
end)
local con4
con4 = Button4.Touched:Connect(function(Hit)
if Hit.Parent == hit.Parent then--Check if its the same model touching
con4:Disconnect()
Button4.Color = Color3.fromRGB(38, 38, 38)
Button4.Material = "Metal"
buttonPressed.Value = buttonPressed.Value + 1
end
end)
firstTouched = false
end
end)