Currently working on a taser.
Down at line 41 to 46, I have a loop every 1 tick so that they cant jump as soon as they get shot. The issue I found was that it kept looping no matter what, I probably should have seen this coming. how would I get it so that after a second or 2 it stops looping?
(scroll down I added comments for line 43 and 46)
local tool = script.Parent
local shoot_part = tool:WaitForChild("Shoot")
local remote = tool:WaitForChild("OnShoot")
local ammoCount = script.Parent:WaitForChild("AmmoCount")
local Workspace = game:GetService("Workspace")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local updateAmmo = ReplicatedStorage.UpdateAmmo
ammoCount.Value = 1
remote.OnServerEvent:Connect(function(player, position)
print("Taser fired")
local origin = shoot_part.Position
local direction = (position - origin).Unit*250
local result = Workspace:Raycast(origin, direction)
if ammoCount.Value < 1 then
ammoCount.Value = 1
wait(2)
else
ammoCount.Value -= 1
print("ammo used")
local intersection = result and result.Position or origin + direction
local distance = (origin - intersection).Magnitude
local bullet_clone = ReplicatedStorage.Bullet:Clone()
bullet_clone.Size = Vector3.new(0.1, 0.1, distance)
bullet_clone.CFrame = CFrame.new(origin, intersection)*CFrame.new(0, 0, -distance/2)
bullet_clone.Parent = Workspace
bullet_clone.Anchored = true
bullet_clone.CanCollide = false
if result then
print("if result")
local part = result.Instance
local humanoid = part.Parent:FindFirstChild("Humanoid") or part.Parent.Parent:FindFirstChild("Humanoid")
local function sit()
humanoid.Sit = true
end
if humanoid then
print("humanoid tasered")
while wait(1) do -- line 43
sit()
print("looping the sit")
end -- line 46
print("Destroying bullet clone")
wait(1)
bullet_clone:Destroy()
print("destroyed bullet clone")
else
print("Destroying bullet clone2")
wait(1)
bullet_clone:Destroy()
print("destroyed bullet clone2")
end
end
end
end)