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)
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)
Hello. Either you didn't call the function or something is wrong in your ServerScript
.