#problems with code
11 messages · Page 1 of 1 (latest)
** You are now Level 15! **
is caused
by being cloned
multi times
by the OnServerEvent
event handler being connected inside the Shoot function
every time the Shoot function is called a new event handler is connected to the Shot event, so when the Shot event is fired all of the connected event handlers are triggered causing multiple Hole objects to be cloned
try this instead
local Animation = nil
local debounce = true
local reloading = false
local Stats_ = {
cooldown = 0.2,
reloadtime = 2.5,
damage = 20,
maxammo = 6
}
script.Parent.Equipped:Connect(function()
Animation = script.Parent.Parent.Humanoid.Animator:LoadAnimation(script.Parent.Idle)
Animation:Play()
end)
script.Parent.Unequipped:Connect(function()
Animation:Stop()
end)
function Shoot()
debounce = false
script.Parent.Handle.Shoot:Play()
script.Parent.Parent.Humanoid.Animator:LoadAnimation(script.Parent.Shoot):Play()
script.Parent.Handle.Attachment.MuzzleFlash:Emit(100)
script.Parent.Ammo.Value = script.Parent.Ammo.Value - 1
script.Shot:FireClient(game.Players:GetPlayerFromCharacter(script.Parent.Parent))
task.wait(Stats_.cooldown)
debounce = true
end
function Reload()
if debounce == true then
reloading = true
script.Parent.Handle.Reload:Play()
task.wait(Stats_.reloadtime)
script.Parent.Ammo.Value = Stats_.maxammo
reloading = false
end
end
script.Shot.OnServerEvent:Connect(function(plr,hit,target,ray)
local Clone = game.ServerStorage.Hole:Clone()
Clone.Parent = workspace
game:GetService("Debris"):AddItem(Clone,10)
Clone.CFrame = hit
Clone.Orientation = target.Orientation
local Weld = Instance.new("WeldConstraint",Clone)
Weld.Part0 = target
Weld.Part1 = Clone
end)
script.Parent.Activated:Connect(function()
if debounce == true and reloading == false then
if script.Parent.Ammo.Value > 0 then
Shoot()
else
Reload()
end
end
end)
thanks