Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

3 comments

0

Show the event listener, the problem lies there, not in your local script.

0

oh ok, i've added it

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

2 answers

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)

3 comments

0

btw the event is very unsafe, when a exploiter fire it he gets strength

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?

0

Maybe you can add: hum:TakeDamage(10 * Strength.Value) (You have to define the Strength before that btw)

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

2 comments

0

It's a local script, not a server script..

0

He used :FireSever()... Do more looking before you downvote someone.

This discussion is preserved as it was. New answers, comments, and votes are closed.