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

How do i increase a IntValue in playerstats by left clicking?

  1. So basically i have this punch script and i would like to make it so when you punch your strength goes up in leaderstats. How do i go about adding to that value everytime left click is fired.

2)How do i add a delay for the animation so it is not spammed, I tried with wait(10) but that did nothing

Heres the animaton script

local Plr = game.Players.LocalPlayer
local UserInputService = game:GetService("UserInputService")
local Char = Plr.Character or Plr.CharacterAdded:Wait()
local Humanoid = Char:WaitForChild("Humanoid")
local Anim = Instance.new("Animation")
Anim.AnimationId = "rbxassetid://5005123017"
local track = Humanoid:LoadAnimation(Anim)

UserInputService.InputBegan:Connect(function(InputObject)
  if InputObject.UserInputType == Enum.UserInputType.MouseButton1 then
    track:Play()
    wait(10)
  end
end)

And heres my leaderstat(forgot to add)

function onPlayerEntered(newPlayer)
	wait(.5)
	local stats = Instance.new("IntValue")
	stats.Name = "leaderstats"

	local strength = Instance.new("IntValue")
	
	strength.Name = "Strength"
	strength.Value = 0

	strength.Parent = stats	
	stats.Parent = newPlayer
end

game.Players.ChildAdded:connect(onPlayerEntered)

1 answer

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

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
    local Leaderstats = Player:WaitForChild("leaderstats")
    local Strength = Leaderstats:FindFirstChild("Strength")
    if (Strength) then
        Strength.Value = (Strength.Value + 1)
    end
    AnimationTrack:Play()
end

Mouse.Button1Down:Connect(PunchAndAddStrength)

3 comments

0

Wouldn't you need a RemoteEvent to increase their stats? Since you're increasing their stats in a local script it won't replicate to the Server.

0

Yes you would

0

I just started scripting today so im not sure what exactly to do, does your script require a remote event? if so i'll read up on it and try it out

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