this is my script; i tried to detect when it hits and stop it from being hit over and over and it keeps doing that. also, the leaderstats don't add, any solution? thanks
for i, v in pairs(Cloned_Cube.Squares:GetChildren()) do
local db = false
v.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and db == false then
db = true
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player.TeamColor.Color ~= v.Color then
local effect = Instance.new("Sound", workspace)
effect.SoundId = "rbxassetid://5893607560"
effect.Volume = 0.6
effect.Playing = true
v.Color = player.TeamColor.Color
player.leaderstats.Tiles.Value += 1
if v.Color ~= Color3.fromRGB(63, 64, 68) and v.Color ~= Color3.fromRGB(202, 203, 209) then
if v.Color == Color3.fromRGB(4, 175, 236) and player.TeamColor.Color ~= v.Color then -- Blue team
local player = Blue_Team:GetPlayers()[math.random(1, #Blue_Team:GetPlayers())]
player.leaderstats.Tiles.Value += -1
elseif v.Color == Color3.fromRGB(0, 255, 0) and player.TeamColor.Color ~= v.Color then -- Green
local player = Green_Team:GetPlayers()[math.random(1, #Green_Team:GetPlayers())]
player.leaderstats.Tiles.Value += -1
elseif v.Color == Color3.fromRGB(255, 102, 204) and player.TeamColor.Color ~= v.Color then --Pink
local player = Pink_Team:GetPlayers()[math.random(1, #Pink_Team:GetPlayers())]
player.leaderstats.Tiles.Value += -1
end
end
wait(0.4)
effect:Destroy()
db = false
end
end
end)

2 comments
Is this in the server or the client? (is this a server script or LocalScript)
If it's the client, you should learn RemoteEvents and read the Client-To-Server model, https://developer.roblox.com/en-us/articles/Roblox-Client-Server-Model