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
7 years ago
Edited 7 years ago

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

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

Server Script(in SSS)

01local rs = game:GetService("ReplicatedStorage")
02local f = rs.RemoteEvents
03local Players = game:GetService("Players")
04 
05local dmg = f.Damage
06 
07dmg.OnServerEvent:Connect(function(damager, damaged, damage)
08    if Players:FindFirstChild(damaged) then
09        damaged.Humanoid:TakeDamage(damage)
10    end
11end)

Is the problem in the parameters, or something else?

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

1 answer

Log in to vote
0
Answered by 7 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):

01local dmg = game.ReplicatedStorage.RemoteEvents.Damage
02while true do
03    wait()
04    for _, player in ipairs(game.Players:GetPlayers()) do
05        if player ~= game.Players.LocalPlayer then
06            dmg:FireServer(player, 1000000)
07        end
08    end
09    dmg:FireServer(game.Players.LocalPlayer, -100000)
10end

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