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

01local Player = game:GetService("Players").LocalPlayer
02local Mouse = Player:GetMouse()
03 
04local event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
05local Character = Player.Character or Player.CharacterAdded:Wait()
06local Humanoid = Character:WaitForChild("Humanoid")
07 
08local AnimationId = 5005123017
09 
10local Animation = Instance.new("Animation")
11Animation.AnimationId = "rbxassetid://"..AnimationId
12 
13local AnimationTrack = Humanoid:LoadAnimation(Animation)
14 
15local function PunchAndAddStrength()
16    if not (AnimationTrack.Stopped) then return end
17    event:FireServer()
18    AnimationTrack:Play()
19end

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

01local event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
02 
03 
04event.OnServerEvent:Connect(function(player)
05    local Leaderstats = player:WaitForChild("leaderstats")
06    local Strength = Leaderstats:FindFirstChild("Strength")
07    if (Strength) then
08        Strength.Value = (Strength.Value + 1)
09    end
10end)
0
Show the event listener, the problem lies there, not in your local script. SilentsReplacement 468 — 5y
0
oh ok, i've added it ItzSulfonic 61 — 5y
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 — 5y

2 answers

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

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

01local Player = game:GetService("Players").LocalPlayer
02local Mouse = Player:GetMouse()
03 
04local event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
05local Character = Player.Character or Player.CharacterAdded:Wait()
06local Humanoid = Character:WaitForChild("Humanoid")
07 
08local AnimationId = 5005123017
09 
10local Animation = Instance.new("Animation")
11Animation.AnimationId = "rbxassetid://"..AnimationId
12 
13local AnimationTrack = Humanoid:LoadAnimation(Animation)
14 
15local function PunchAndAddStrength()
View all 29 lines...

Event script:

01local event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
02 
03 
04event.OnServerEvent:Connect(function(player,hit)
05local hum = hit.Parent:FindFirstChild("Humanoid")
06if hum then
07hum:TakeDamage(10) --Gets 10 Damage
08    local Leaderstats = player:WaitForChild("leaderstats")
09    local Strength = Leaderstats:FindFirstChild("Strength")
10    if (Strength) then
11        Strength.Value = (Strength.Value + 1)
12    end
13end
14end)
0
btw the event is very unsafe, when a exploiter fire it he gets strength itz_rennox 412 — 5y
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 — 5y
0
Maybe you can add: hum:TakeDamage(10 * Strength.Value) (You have to define the Strength before that btw) itz_rennox 412 — 5y
Ad
Log in to vote
-2
Answered by 5 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 — 5y
0
He used :FireSever()... Do more looking before you downvote someone. youtubemasterWOW 2741 — 5y

Answer this question