I’m creating a leaf blower to blow leaf monsters apart, but the mouse events doesn’t seem to be firing. I’m using a script, not a localscript. I don’t see any errors about this in the developer log.
Can anyone tell me why?
repeat wait() until game:IsLoaded()
local mouse = script.Parent.Parent.Parent:GetMouse() -- Gets mouse from player
local a = false
script.Parent.Equipped:Connect(function()
a = true
end)
script.Parent.Unequipped:Connect(function()
a = false
end)
mouse.Button1Down:Connect(function() -- Doesn't seem to be firing this function
if a == true then
script.Parent.wind.wind.Volume = 1
script.Parent.killpart.Script.Disabled = false
script.Parent.wind.ParticleEmitter.Enabled = true
script.Parent.wind.wind:Play()
end
end)
mouse.Button1Up:Connect(function()
if a == true then
script.Parent.killpart.Script.Disabled = true
script.Parent.wind.ParticleEmitter.Enabled = false
for i = 1, 0, 0.1 do
script.Parent.wind.wind.Volume = i
wait(0)
end
script.Parent.wind.wind:Stop()
script.Parent.wind.wind.Volume = 1
end
end)
GetMouse doesn’t support global scripts unfortunately. my solution would be putting the code in a local script and make remote events that would be fired by global scripts when you click.
The code would probably look like this:
-- local script
repeat wait() until game:IsLoaded()
local mouse = game.Players.LocalPlayer:GetMouse() -- Gets mouse from player
local a = false
script.Parent.Equipped:Connect(function()
a = true
end)
script.Parent.Unequipped:Connect(function()
a = false
end)
mouse.Button1Down:Connect(function() -- Doesn't seem to be firing this function
script.Parent.button1downevent:FireServer()
end)
mouse.Button1Up:Connect(function()
script.Parent.button1upevent:FireServer()
end)
-- global script
local a = true
script.Parent.button1downevent.OnServerEvent:Connect(function()
if a == true then
script.Parent.wind.wind.Volume = 1
script.Parent.killpart.Script.Disabled = false
script.Parent.wind.ParticleEmitter.Enabled = true
script.Parent.wind.wind:Play()
end
end)
script.Parent.button1upevent.OnServerEvent:Connect(function()
if a == true then
script.Parent.killpart.Script.Disabled = true
script.Parent.wind.ParticleEmitter.Enabled = false
for i = 1, 0, 0.1 do
script.Parent.wind.wind.Volume = i
wait(0)
end
script.Parent.wind.wind:Stop()
script.Parent.wind.wind.Volume = 1
end
end)
what it would look like in tool:
this probably isn’t the most inefficient way of doing it, but if it works, it works.