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

How do i make it so you can deal damage to another player?

Asked by 4 years ago
Edited 4 years ago

This is my punch animation script, i want to make it so when you hit someone it does damage. And the amount of damage you do depends on your stat which i have in leaderstats. For example i want it so someone with 100 strength does more damage than someone with 25 strength, etc. But i can't figure out how to script it out or where to put in.

local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()

local event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

local AnimationId = 5005123017

local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://"..AnimationId

local AnimationTrack = Humanoid:LoadAnimation(Animation)

local function PunchAndAddStrength()
    if not (AnimationTrack.Stopped) then return end
    event:FireServer()
    AnimationTrack:Play()
end

I just started really scripting yesterday so most stuff is confusing for me.

local event = game.ReplicatedStorage:WaitForChild("RemoteEvent")


event.OnServerEvent:Connect(function(player)
    local Leaderstats = player:WaitForChild("leaderstats")
    local Strength = Leaderstats:FindFirstChild("Strength")
    if (Strength) then
        Strength.Value = (Strength.Value + 1)
    end
end)
0
Show the event listener, the problem lies there, not in your local script. SilentsReplacement 468 — 4y
0
oh ok, i've added it ItzSulfonic 61 — 4y
0
Theres no problem i just don't know how to write a script that causes damage along with making the damage go up the more strength you have ItzSulfonic 61 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Well, I never did punch scripts that much but tI will try it

local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()

local event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

local AnimationId = 5005123017

local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://"..AnimationId

local AnimationTrack = Humanoid:LoadAnimation(Animation)

local function PunchAndAddStrength()
    if not (AnimationTrack.Stopped) then return end
    AnimationTrack:Play()
Character.RightHand.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
event:FireServer(hit)
end
end)

Character.LeftHand.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
event:FireServer(hit)
end
end)
end

Event script:

local event = game.ReplicatedStorage:WaitForChild("RemoteEvent")


event.OnServerEvent:Connect(function(player,hit)
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum then
hum:TakeDamage(10) --Gets 10 Damage
    local Leaderstats = player:WaitForChild("leaderstats")
    local Strength = Leaderstats:FindFirstChild("Strength")
    if (Strength) then
        Strength.Value = (Strength.Value + 1)
    end
end
end)
0
btw the event is very unsafe, when a exploiter fire it he gets strength itz_rennox 412 — 4y
0
Is there a way i can protect the event from an exploiter and how can i make it so the more strength you have the more damage you do? ItzSulfonic 61 — 4y
0
Maybe you can add: hum:TakeDamage(10 * Strength.Value) (You have to define the Strength before that btw) itz_rennox 412 — 4y
Ad
Log in to vote
-2
Answered by 4 years ago

Hello. Either you didn't call the function or something is wrong in your ServerScript.

0
It's a local script, not a server script.. SilentsReplacement 468 — 4y
0
He used :FireSever()... Do more looking before you downvote someone. youtubemasterWOW 2741 — 4y

Answer this question