Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make this handle dissappear after touch?

Asked by 6 years ago
Edited 6 years ago
local player = game.Players.LocalPlayer
local handle = script.Parent.Handle
local debounce = false
handle.Touched:Connect(function(hit)
    if not debounce and hit and hit.Parent.Humanoid then
        debounce = true
        hit.Parent.Humanoid:TakeDamage(40)
       wait(10)
       debounce = false
    end
end)

This is a local script called Damage in my tool How would I make the handle disappear after hit

Also please feel free for tips and advice, will gladly accept them.

0
fix ur lua tags DinozCreates 1070 — 6y
0
can you reformat your question? tonyv537 95 — 6y
0
well after hit or damage, either put Handle.Transparency = 0 or Handle:Destroy() tonyv537 95 — 6y

1 answer

Log in to vote
0
Answered by
Imperialy 149
6 years ago

Your code wont replicate; you are using a localscript to damage which will not work but here Add a remote event into your tool and a Serverscript.

LocalScript:

local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local event = tool:WaitForChild("RemoteEvent")
local uis = game:GetService("UserInputService")
local canhit = true
uis.InputBegan:Connect(function(Input,gameProcessed)
    if not gameProcessed then
        if Input.UserInputType == Enum.UserInputType.MouseButton1 and canhit then
            event:FireServer()
            canhit = false
            wait(10)
            canhit = true
        end
    end
end)

Paste this code into your serverscript

Server Script:

local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local event = handle:WaitForChild("RemoteEvent")
local canhit = true
local damaged = false
event.OnServerEvent:Connect(function(player,arg1,arg2)
    if canhit then
        Handle.Touched:Connect(function(hit)
            local hum = hi.Parent:FindFirstChildOfClass("Humanoid")
            if hum and not damaged then
                hum:TakeDamage(40)
                damaged = true
                handle.Transparency = 1
            end
        end)
        wait(10)
        damaged = false
        canhit = true
        handle.Transparency = 0
    end
end)
Ad

Answer this question