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?
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:
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.