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

Why doesn't the sword give damage on attack?

Asked by 5 years ago

Hello, I'm trying to make a custom sword. The problem is the scripting, the sword won't give damage to another humanoid. Help?

--LOCAL SCRIPT--

wait()

script.Parent.blade.Touched:Connect(function(h)

game.ReplicatedStorage.RemoteEventz.AttackToolE:FireServer(15, h)
end)
--SERVER SCRIPT--

wait()

Debounce = false

    game.ReplicatedStorage.RemoteEventz.AttackToolE.OnServerEvent:Connect(function(plr, Damage, Target)
if Target.Parent:FindFirstChild('Humanoid') and Target.Parent.Name ~= plr.Name and Debounce == true then
        Debounce = false
        local enemy = Target.Parent.Humanoid
        enemy:TakeDamage(Damage)
        wait(1.5)
        Debounce = true
    end
end)
0
your remote event communication is extremely unsecure, some exploiter can loop through every player and kill them User#23365 30 — 5y
0
Looks like you misspelled RemoteEvents in the LocalScript. exxtremestuffs 380 — 5y

2 answers

Log in to vote
3
Answered by 5 years ago
Edited 5 years ago

RemoteEvent Communication

your communication between the client and server is very unsecure as some exploiter can just loop through every player and kill them like this:

for _,v in pairs(game.Players:GetPlayers()) do
    game.ReplicatedStorage.RemoteEventz.AttackToolE:FireServer(-9999999999,v.Character.HumanoidRootPart)
end

and they'd pretty much just ruin the entire server. You could just do all of this on the client, since it replicates to every client when you use :TakeDamage() on a player. Also why your script didnt work is because you did and Debounce == true then though your boolean is set to false without any line setting it to true before the if statement.

LocalScript

--client script 

local Debounce = false
local player = game.Players.LocalPlayer

script.Parent.blade.Touched:Connect(function(h)
    if h.Parent:FindFirstChildOfClass("Humanoid") and hit.Parent ~= player.Character and Debounce == false then
        Debounce = true
        local enemy = h.Parent.Humanoid

        enemy:TakeDamage(15)
        wait(1.5)
        Debounce = false
    end
end)
0
This would not work since damage doesn't replicate. poke7667 142 — 5y
0
I can see where you are coming from with the exploiting. However, you aren't solving anything anyways since there is no communication with the server. What he/she should do is in the server script, automatically make the damage 15 and possibly create a distance checker (or some other check) to figure out if a player is actually hitting the player indicated. poke7667 142 — 5y
Ad
Log in to vote
0
Answered by
poke7667 142
5 years ago
Edited 5 years ago

Your issue is your debounce in the server script.

wait()

Debounce = false

    game.ReplicatedStorage.RemoteEventz.AttackToolE.OnServerEvent:Connect(function(plr, Damage, Target)
if Target.Parent:FindFirstChild('Humanoid') and Target.Parent.Name ~= plr.Name and Debounce == true then
        Debounce = false
        local enemy = Target.Parent.Humanoid
        enemy:TakeDamage(Damage)
        wait(1.5)
        Debounce = true
    end
end)

The debounce is first defined as false. However, you check if the debounce is ever true Debounce == true. The debounce never changes to true, hence why the damage never gets taken by another player.

Answer this question