Im creating a RPG that gives the player stats like strength, dexterity and such and I want these stats to affect sword and weapon damage. Ive learned the basics of remote events and how to send values to a server script by reading over a free model shop script, but I have no clue how to send to the server an enemys humanoid and how to have the server actually take health from them.
local sword script
script.Parent.Changed:Wait(.3)
local tool = script.Parent
local config = tool.config
local minda = config.minda
local maxda = config.maxda
local player = game.Players.LocalPlayer
local stats = player:WaitForChild("playerstats")
local slashanim = script.Parent.anim:WaitForChild("SlashAnim")
local slashanim2 = script.Parent.anim:WaitForChild("SlashAnim2")
local slashsound = script.Parent.Handle:WaitForChild("swordsound")
local player = game.Players.LocalPlayer
local Character = script.Parent.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local sword = script.Parent
local blade = sword.blade
print "hey"
local damage = game.ReplicatedStorage.remotes.damage:WaitForChild("normal")
script.Parent.Activated:Connect(function(attack)
slashsound:Play()
damage:FireServer(minda.Value, maxda.Value)
print "hey1"
end)
print "hey2"
minda and maxda are minimal damage and max damage
server side script
local normal = game.ReplicatedStorage.remotes.damage.normal
normal.OnServerEvent:Connect(function(player, minda, maxda)
local stats = player.playerstats
local strn = stats.strength
local dex = stats.dexterity
local focus = stats.focus
local health = stats.health
local manac = stats.manac
end)
I dont have much going on because I want to know how to send the damage value before i continue. God bless friends
Edit : Here is the correct code for anyone with the same problem
local damage = game.ReplicatedStorage.RemoteEvents.damage --set to whereever your damage remote event is
damage.OnServerEvent:Connect(function(player, weapondamage, enemyattacked) --weapon damage refers to the tools damage you set and enemyattacked is the npc/player touched
local stats = player.playerstats --or leaderstats
local strn = stats.strength --these can be whatever you want to affect damage
local dex = stats.dexterity --these can be whatever you want to affect damage
local Humanoid = enemyattacked.Character.Humanoid
local damage = weapondamage + strn.Value --or dex.Value. we didnt do weapondamage.value because in the tool, we sent weapondamage.Value
Humanoid:TakeDamage(damage) --You could just have the humanoid(the enemyattacked) health set, but takedamage is the proper way, not allow you to attack through forcefields and such.
end)
if you dont want your weapon to deal damage to other players, simple added
if not game:GetService("Players"):GetPlayerFromCharacter(enemyattacked.Parent) then
above "local stats=..." and an extra end. God bless mates

1 comment
answering