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

Which part of the damage script won't work?

Asked by
Viking359 161
6 years ago
Edited 6 years ago

Everything in my sword script works fine, except for the damage. Local Script (damaging part, directly inside tool):

local damage = script.Parent.Damage.Value
local re = f:WaitForChild("Damage")
local damager = player--many of the variables are defined in a different part of the script
local handle = script.Parent.Handle
handle.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") and attacking == true then
        local damaged = hit.Parent
    re:FireServer(damager, damaged, damage)
    attacking = false--gets reset somewhere else
    end
end)

Server Script(in SSS)

local rs = game:GetService("ReplicatedStorage")
local f = rs.RemoteEvents
local Players = game:GetService("Players")

local dmg = f.Damage

dmg.OnServerEvent:Connect(function(damager, damaged, damage)
    if Players:FindFirstChild(damaged) then
        damaged.Humanoid:TakeDamage(damage)
    end
end)

Is the problem in the parameters, or something else?

0
The server needs to apply the damage not the client. User#5423 17 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Your immediate problem can be fixed by removing damager from the FireServer call -- the LocalPlayer is already given to the server script by Roblox, so if you send it again, the server ends up with the first two parameters being the same.

Next, your server script isn't finding the player to damage correctly. FindFirstChild takes in a name, not an instance - a simple fix is to have damaged.Name instead of damaged on that line.

A potentially big problem is one that you won't run into unless your game attracts exploiters. The rule with RemoteEvents is to assume that someone will have complete scriptual access to every RemoteEvent you make (ie they can trigger any RemoteEvent/RemoteFunction with any arguments they want, as many times as they want). ex, imagine that an exploiter ran this script in your place (which they could do):

local dmg = game.ReplicatedStorage.RemoteEvents.Damage
while true do
    wait()
    for _, player in ipairs(game.Players:GetPlayers()) do
        if player ~= game.Players.LocalPlayer then
            dmg:FireServer(player, 1000000)
        end
    end
    dmg:FireServer(game.Players.LocalPlayer, -100000)
end

Everyone is now being constantly killed except the exploiter (who is continually healing himself) and your server would be happily accepting these commands! Things to do:

  • The server should know the damage level; it doesn't need the client to tell it. You should be able to look up the weapon that the player is currently using and how much damage it is supposed to do.
  • Ideally, make sure that the player is at least near the person they are theoretically damaging. Also make sure that players aren't teleporting around too much (an exploiter should be able to do this with ease).
  • Consider keeping track of weapon cooldowns so that an exploiter can't attack more frequently than you want them to.

Do note that just because a player has requested to attack while on cooldown, that doesn't prove that they're an exploiter (even if you have code in the LocalScripts to respect cooldown as well) -- lag can play a part. Similarly, the server may see characters appear to "teleport" short distances legitimately if the client had a lag-spike.

Ad

Answer this question