I am trying to make a bush movement system. I am trying to make the bush randomly tweak and turn when a player walks in and out of the bush but for some reason, it keeps running the .Touched
function and completely ignores the debounce that I have implemented. Here is what I mean and this is my code currently!
`
local TweenService = game:GetService(“TweenService”)
local Sound = script:FindFirstChild(“Foliage Movement 1 (SFX)”)
local Debounce = true
script.Parent.Touched:Connect(function(hit)
if game.Players:FindFirstChild(hit.Parent.Name) then
local Player = game.Players:FindFirstChild(hit.Parent.Name)
if Player then
if Debounce == true then
Debounce = false
local RandomVector = Vector3.new(math.random() * 10,math.random() * 10,math.random() * 3)
local tween = TweenService:Create(script.Parent,TweenInfo.new(.2,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut,0,false,0),{Orientation = RandomVector})
local tween2 = TweenService:Create(script.Parent,TweenInfo.new(.2,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut,0,false,0),{Orientation = Vector3.new(1.516, 31.97, -2.428)})
tween:Play()
Sound:Play()
tween.Completed:Wait()
tween2:Play()
tween2.Completed:Wait()
end
end
end
end)
script.Parent.TouchEnded:Connect(function(hit)
if game.Players:FindFirstChild(hit.Parent.Name) then
local Player = game.Players:FindFirstChild(hit.Parent.Name)
if Player then
if Debounce == false then
Debounce = true
local RandomVector = Vector3.new(math.random() * 10,math.random() * 10,math.random() * 3)
local tween = TweenService:Create(script.Parent,TweenInfo.new(.2,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut,0,false,0),{Orientation = RandomVector})
local tween2 = TweenService:Create(script.Parent,TweenInfo.new(.2,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut,0,false,0),{Orientation = Vector3.new(1.516, 31.97, -2.428)})
tween:Play()
Sound:Play()
tween.Completed:Wait()
tween2:Play()
tween2.Completed:Wait()
end
end
end
end)
`
P.S. Idk why it isnt all going into these brackets