I’m trying to make these pads where when a player walks on them it adds them to a players table and when the walk off it, it removes them. This works but I have this annoying issue where it keeps firing even though my character isn’t moving. I’ve tried region 3 but you have to use loops etc and I’d rather not because I’m worried it will use a lot of server memory but if I have to I will. Anyways how do I fix this?
Note: If a player is already on a pad another player cannot come and take their position while they are still standing on it.
Thanks, Alpha
local Player1Pad = script.Parent:WaitForChild("Player1") --Pad you walk on
local Player2Pad = script.Parent:WaitForChild("Player2")
local Players = {}
Player1Pad.Touched:Connect(function(HitInstance)
print(HitInstance)
if HitInstance.Parent:FindFirstChild("Humanoid") then
if Players[1] == nil then
table.insert(Players, game.Players[HitInstance.Parent.Name])
Player1Pad.Material = Enum.Material.Neon
local Goal = {} Goal.Color = Color3.fromRGB(0, 100, 165)
local Tween = game:GetService("TweenService"):Create(Player1Pad, TweenInfo.new(0.5), Goal)
Tween:Play()
wait(1)
else
for i, Player in pairs(Players) do
if Player.Name ~= HitInstance.Parent.Name then
table.insert(Players, game.Players[HitInstance.Parent.Name])
Player1Pad.Material = Enum.Material.Neon
local Goal = {} Goal.Color = Color3.fromRGB(0, 100, 165)
local Tween = game:GetService("TweenService"):Create(Player1Pad, TweenInfo.new(0.5), Goal)
Tween:Play()
wait(1)
end
end
end
end
end)
Player1Pad.TouchEnded:Connect(function(HitInstance)
if HitInstance.Parent:FindFirstChild("Humanoid") then
for i, Player in pairs(Players) do
if Player.Name == HitInstance.Parent.Name then
table.remove(Players, i)
Player1Pad.Material = Enum.Material.SmoothPlastic
local Goal = {} Goal.Color = Color3.fromRGB(163, 162, 165)
local Tween = game:GetService("TweenService"):Create(Player1Pad, TweenInfo.new(0.5), Goal)
Tween:Play()
wait(3)
end
end
end
end)