So, Im trying to make a automatic gun with this but it doesn’t seem to work can someone help me out?
local mouse = game.Players.LocalPlayer:GetMouse()
local down = false
script.Parent.Activated:Connect(function()
down = true
end)
script.Parent.Deactivated:Connect(function()
down = false
end)
while down do
game.ReplicatedStorage.Events.Shoot:FireServer(script.Parent,mouse.Target)
wait()
end
The problem is that down is initially false. This means the while loop will never actually run. The best thing to do is to make a connection in the Activated event and disconnect it in the Deactivated event
so something like this? if this works then it might be due to server scripts
local mouse = game.Players.LocalPlayer:GetMouse()
local down = false
script.Parent.Activated:Connect(function()
down = true
repeat game.ReplicatedStorage.Events.Shoot:FireServer(script.Parent,mouse.Target) wait() until not down
end)
script.Parent.Deactivated:Connect(function()
down = false
end)
You should use an if statement to make sure you are only setting down to true if down is not true and vice versa. Other than that, it looks good!
local mouse = game.Players.LocalPlayer:GetMouse()
local down = false
script.Parent.Activated:Connect(function()
if not down then
down = true
repeat game.ReplicatedStorage.Events.Shoot:FireServer(script.Parent,mouse.Target) wait() until not down
end
end)
script.Parent.Deactivated:Connect(function()
if down then
down = false
end
end)