I would like to enable or disable a moving part with players in a table.
This is my goal when a player touches a block it add the player name to a table.
the event or action is triggered.
when the player touches a stop block the player is removed from the table and the event stops.
When there are 2 players in the table the event should be triggered,
when 1 player touches the stop
the event should still be triggered and only stop when both players touch stop.
I have a script that works for one player, but when 1 player touches the stop it stops
the event for all players.
Thanks
local PlayerTable = {}
local finish = script.Parent.Parent.StopTrigger
local start = script.Parent.Parent.StartTrigger
local killbrick = game:GetService("Workspace").TurnRock.KillBrick
start.Touched:Connect(function(Hit)
local Humanoid = Hit.Parent:FindFirstChildOfClass("Humanoid")
if Humanoid and Humanoid.Health ~= 0 then
local Player = Players:GetPlayerFromCharacter(Hit.Parent)
if not PlayerTable[Player.Name] then
script.Parent.Parent.Base01.HingeConstraint.MotorMaxTorque = 10000000
script.Parent.Parent.Base01.HingeConstraint.AngularVelocity = 0.1
print(script.Parent.Parent.Base01.HingeConstraint.AngularVelocity)
print("Adding " .. Player.Name .. " to the table")
PlayerTable[Player.Name] = Player
for i, val in pairs(PlayerTable) do
print(i, val)
end
end
end
end)
finish.Touched:Connect(function(hit)
local Humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
local Player = Players:GetPlayerFromCharacter(hit.Parent)
print("Player Touched Finish Block!")
if PlayerTable[Player.Name] then
for key, val in pairs(PlayerTable) do
script.Parent.Parent.Base01.HingeConstraint.MotorMaxTorque = 0
script.Parent.Parent.Base01.HingeConstraint.AngularVelocity = 0
print((key).." Key")
print(val)
if Player.Name == key then
print("Pass")
PlayerTable[key] = nil
print("Removing " .. Player.Name .. " from the table")
end
end
end
end)