Hello everyone,
I’ve decided on practicing making melee weapons, and I’m stuck on whether
or not the system I’ve created is actually good.
This LocalScript has 2 parts:
The .Activated event which sets a value to true and sets it back to false
after a second, and the .Touched event which will run code whether or
not the value from the .Activated event is set to true or not.
Here’s the code I’ve come up with:
local tool = script.Parent
local isActive = false
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local function onActivate()
if isActive == false then
isActive = true
print("Tool Activated!")
wait(1)
isActive = false
end
end
local function onTouched(hit)
if isActive == true and hit.Parent:FindFirstChild("Humanoid") then
isActive = false
print("Tool Used!")
ReplicatedStorage.DamageEvent:FireServer(hit.Parent:FindFirstChild("Humanoid"))
-- Do stuff
end
end
tool.Activated:Connect(onActivate)
tool.Handle.Touched:Connect(onTouched)
I also have a ServerScript which just damages the humanoid:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
ReplicatedStorage.DamageEvent.OnServerEvent:Connect(function(player, humanoid)
humanoid:TakeDamage(20)
end)
I have plans to secure this RemoteEvent from exploiters but first I want to make this localscript better than it is right now.