-
What do you want to achieve?
I want to make a tool that can grapple players -
What is the issue?
Video: touched problem
The script only works half the time and the touched still works when it shouldn’t. -
What solutions have you tried so far?
I tried using region three and other solutions like that by looking at things on the dev forum, but I had the same problem then as now.I’ve looked on the dev forum and other websites but haven’t found a solution.
local welding
local enabled
local Time = 0
tool.throw.OnServerEvent:Connect(function(plr,part,d)
Time = 0
enabled=true
print("fired")
if enabled==true then
part.Touched:Connect(function(hit)
print("touched")
welding=true
if Time == 0 and enabled==true then
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("Alreadyhit")==nil and welding==true and hit.Parent~=tool.Parent then --grab player
welding=false
enabled=false
print(welding, enabled)
----------------------------------------------------------------------------------------------------------------------
local vCharacter = tool.Parent
local vPlayer = game.Players:GetPlayerFromCharacter(vCharacter)
local hitPlayer = game.Players:GetPlayerFromCharacter(hit.Parent)
local hitcharacter = hit.Parent
local Humanoid = hitcharacter:WaitForChild("Humanoid")
local Stunned =Humanoid.Stunned
local HRP=hitcharacter:FindFirstChild("HumanoidRootPart")
local Check = Instance.new("IntValue", hitcharacter)
local SliceSound=script:WaitForChild("Blade Slice"):Clone()
----------------------------------------------------------------------------------------------------------------------
if HRP:FindFirstChild("Body Attachment")==nil then
local Batt=Instance.new("Attachment" ,hitcharacter:FindFirstChild("HumanoidRootPart"))
Batt.Name="Body Attachment"
else
end
local function Grab(Player, Playerhit, Target, Targethit, Position1, Position2)
local Weld = Instance.new("Weld", HRP)
Weld.Name="kratosweld"
Weld.Part1 = blade
Weld.Part0 = HRP
Weld.C0 = Position1
Weld.C1 = Position2
game.Debris:AddItem(Weld ,0.7)
Target.Humanoid.Died:Connect(function()
if Target.Humanoid.Health <= 0 then
Player.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, false)
Weld:Destroy()
end
end)
end
----------------------------------------------------------------------------------------------------------------------
Humanoid:TakeDamage(tool.Damage.Value)
hit.Parent.Humanoid.Stunned.StunEvent:FireClient(plr, 3)
tool.catch:FireClient(plr)
vCharacter.HumanoidRootPart.Anchored=true
Check.Name = "Alreadyhit"
game.Debris:AddItem(Check ,0.625)
TagHumanoid(Humanoid, vPlayer)
SliceSound.Parent=HRP
SliceSound.Playing=true
game.Debris:AddItem(SliceSound,script:WaitForChild("Blade Slice").TimeLength)
Grab(tool.Parent, blade, hitcharacter, HRP, CFrame.new(blade.Position), CFrame.new(blade.Position))
task.wait(2)
Stunned.Value=true
task.wait(3)
welding=true
end
end
end)
end
end)
function TagHumanoid(humanoid, player)
local Tag = Instance.new("ObjectValue")
Tag.Name = "creator"
Tag.Value = player
Tag.Parent = humanoid
Debris:AddItem(Tag, 0.25)
task.wait(0.1)
end
while task.wait(1) do
Time = Time + 1
if Time == 0 then
Time = 1
end
end