I have a game where a radius is attached to a player. Whenever it's touching an object, space is hit, and a value is set to 1, it's supposed to perform a function that senses if the radius is touching a brick named "Target," and if so, execute. It works only sometimes. The issue isn't the value, or anything like that. It works on occasion, and other times, it doesn't. I'm not sure why. Here's the script:
wait(0.1)
local canAttack = script.Parent.canAttack
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local radius = game.Players.LocalPlayer.Character.HumanoidRootPart.HomingRadius
local Toggled = false
mouse.KeyDown:connect(function(key)
if key:byte() == 32 and canAttack.Value == 1 then
print(canHoming.Value)
print("homing! attack!")
wait(0)
Toggled = true
Attack()
end
end)
-mouse.KeyDown:connect(function(key)
if key:byte() == 32 and canAttack.Value == 1 then
Toggled = true
print(Toggled)
wait(0.2)
Toggled = false
print(Toggled)
end
end)
function Attack()
radius.Touched:Connect(function(hit)
print(hit.Name)
if hit.Name == "Target" and Toggled == true then
print("I'm executing")
--local target = radius.hit
end
end)
end
