Hello. I am trying to create a gun script but I have seem to run in to a problem. I have a button for mobile players to press in order to reload, but when you press / click the button it just fires anyway. I saw another post similar to this and it had said something about the active property being disabled, I tried enabling it and disabling it but still it did not work correctly.
I have looked on numerous sites. Nothing has been found of this besides the one topic I read.
Here is the code for the local script.
local mouse = game.Players.LocalPlayer:GetMouse()
local ui = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("Ammo").TextLabel
-- CUSTOM --
ammo = 17
fullmag = 17
-- CUSTOM --
local uis = game:GetService("UserInputService")
canshoot = true
script.Parent.Activated:Connect(function()
if canshoot == true then
if ammo > 0 then
ammo = ammo - 1
ui.Text = (ammo.." / ∞")
script.Parent.Shoot:FireServer(mouse.Hit.p)
else
script.Parent.BlankEvent:FireServer()
end
end
end)
uis.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.R then
canshoot = false
script.Parent.ReloadEvent:FireServer()
wait(2)
ammo = fullmag
ui.Text = (ammo.." / ∞")
canshoot = true
end
end)
script.Parent.Equipped:Connect(function()
ui.Visible = true
ui.Parent.FrameI.Visible = true
ui.Parent.Frame.Visible = true
ui.Parent.reload.Visible = true
script.Parent.Equip:FireServer()
end)
script.Parent.Unequipped:Connect(function()
ui.Visible = false
ui.Parent.FrameI.Visible = false
ui.Parent.Frame.Visible = false
ui.Parent.reload.Visible = false
script.Parent.Uneqip:FireServer()
end)
ui.Parent.reload.MouseButton1Click:Connect(function()
if canshoot == true then
if ammo > 0 then
ammo = ammo - 1
ui.Text = (ammo.." / ∞")
script.Parent.Shoot:FireServer(mouse.Hit.p)
else
script.Parent.BlankEvent:FireServer()
end
end
end)
If you know why or how to stop this, please reply. Thanks!