How is this for a sword framework?

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.

1 Like

I would suggest attaching a video of the gameplay of the sword.

2 Likes

That’s a good idea, although I don’t really have recording software. I’ll try to attach one in later though. :wink:

That is insecure because an exploiter can loop DamageEvent and kill everyone.

2 Likes

Thanks! I’ll remember that! I’ll look for some ways to secure my RemoteEvents.

Add multiple sanity checks on the server (magnitude and stuff)

You can’t prevent remotes from being fired.

1 Like

I can see that being useful to have, as too many games forget about this. Thanks for helping me get into the habit of preventing exploits! :smiley:

1 Like