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.
01 | local Player = game:GetService( "Players" ).LocalPlayer |
02 | local Mouse = Player:GetMouse() |
03 |
04 | local event = game.ReplicatedStorage:WaitForChild( "RemoteEvent" ) |
05 | local Character = Player.Character or Player.CharacterAdded:Wait() |
06 | local Humanoid = Character:WaitForChild( "Humanoid" ) |
07 |
08 | local AnimationId = 5005123017 |
09 |
10 | local Animation = Instance.new( "Animation" ) |
11 | Animation.AnimationId = "rbxassetid://" ..AnimationId |
12 |
13 | local AnimationTrack = Humanoid:LoadAnimation(Animation) |
14 |
15 | local function PunchAndAddStrength() |
16 | if not (AnimationTrack.Stopped) then return end |
17 | event:FireServer() |
18 | AnimationTrack:Play() |
19 | end |
I just started really scripting yesterday so most stuff is confusing for me.
01 | local event = game.ReplicatedStorage:WaitForChild( "RemoteEvent" ) |
02 |
03 |
04 | event.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 |
10 | end ) |
Well, I never did punch scripts that much but tI will try it
01 | local Player = game:GetService( "Players" ).LocalPlayer |
02 | local Mouse = Player:GetMouse() |
03 |
04 | local event = game.ReplicatedStorage:WaitForChild( "RemoteEvent" ) |
05 | local Character = Player.Character or Player.CharacterAdded:Wait() |
06 | local Humanoid = Character:WaitForChild( "Humanoid" ) |
07 |
08 | local AnimationId = 5005123017 |
09 |
10 | local Animation = Instance.new( "Animation" ) |
11 | Animation.AnimationId = "rbxassetid://" ..AnimationId |
12 |
13 | local AnimationTrack = Humanoid:LoadAnimation(Animation) |
14 |
15 | local function PunchAndAddStrength() |
Event script:
01 | local event = game.ReplicatedStorage:WaitForChild( "RemoteEvent" ) |
02 |
03 |
04 | event.OnServerEvent:Connect( function (player,hit) |
05 | local hum = hit.Parent:FindFirstChild( "Humanoid" ) |
06 | if hum then |
07 | hum: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 |
13 | end |
14 | end ) |
Hello. Either you didn't call the function or something is wrong in your ServerScript
.