I made a boxing system when you are close to a punching bag (Touching simi transparent part) you can click a GUI to gain strength (there is also multiple bags with different strength requirements to use)
As of right now all it does is if you are inside the simi transparent part and click you get strength points.
How do I add punch animations when punched and make sure the character is facing the punching bag when inside the simi transparent part?
Code:
Server Script (Inside ServerScriptService)
game.Players.PlayerAdded:Connect(function(plr)
local de = Instance.new("BoolValue")
de.Name = "de"
de.Parent = plr
de.Value = false
local CurrentBag = Instance.new("IntValue")
CurrentBag.Name = "CurrentBag"
CurrentBag.Parent = plr
local Char = plr.Character or plr.CharacterAdded:Wait()
local CheckerPart = Instance.new("Part")
CheckerPart.Name = "CheckerPart"
CheckerPart.Parent = Char.HumanoidRootPart
CheckerPart.Size = Vector3.new(0.1, 0.1, 0.1)
CheckerPart.Position = Char.HumanoidRootPart.Position
CheckerPart.Anchored = false
CheckerPart.Transparency = 1
CheckerPart.CanCollide = false
local CheckerPartWeld = Instance.new("WeldConstraint")
CheckerPartWeld.Name = "CheckerPartWeld"
CheckerPartWeld.Parent = Char.HumanoidRootPart.CheckerPart
CheckerPartWeld.Part0 = Char.HumanoidRootPart.CheckerPart
CheckerPartWeld.Part1 = Char.HumanoidRootPart
Char.HumanoidRootPart.CheckerPart.Touched:Connect(function(hit)
if hit == game.Workspace["1"] then
plr.CurrentBag.Value = 1
elseif hit == game.Workspace["2"] then
plr.CurrentBag.Value = 2
elseif hit == game.Workspace["3"] then
plr.CurrentBag.Value = 3
elseif hit == game.Workspace["4"] then
plr.CurrentBag.Value = 4
elseif hit == game.Workspace["5"] then
plr.CurrentBag.Value = 5
end
end)
Char.HumanoidRootPart.CheckerPart.TouchEnded:Connect(function(hit)
if hit == game.Workspace["1"] or hit == game.Workspace["2"] or hit == game.Workspace["3"] or hit == game.Workspace["4"] or hit == game.Workspace["5"] then
plr.CurrentBag.Value = 0
end
end)
end)
Server Script (Inside ServerScriptService)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local BagEvents = ReplicatedStorage:WaitForChild("BagEvents")
BagEvents.A.OnServerEvent:Connect(function(player)
local Character = player.Character or player.CharacterAdded:Wait()
if player.de.Value == false then
player.de.Value = true
player.leaderstats.Strength.Value = player.leaderstats.Strength.Value + 1
local Anim = Instance.new("Animation")
Anim.AnimationId = "http://roblox.com/asset/?id=3246922072"
local PlayAnim = Character.Humanoid:LoadAnimation(Anim)
PlayAnim:Play()
player.de.Value = false
end
end)
BagEvents.B.OnServerEvent:Connect(function(player)
if player.de.Value == false and player.leaderstats.Strength.Value >= 100 then
player.de.Value = true
player.leaderstats.Strength.Value = player.leaderstats.Strength.Value + 20
wait(0.1)
player.de.Value = false
end
end)
BagEvents.C.OnServerEvent:Connect(function(player)
if player.de.Value == false and player.leaderstats.Strength.Value >= 2000 then
player.de.Value = true
player.leaderstats.Strength.Value = player.leaderstats.Strength.Value + 100
wait(0.1)
player.de.Value = false
end
end)
BagEvents.D.OnServerEvent:Connect(function(player)
if player.de.Value == false and player.leaderstats.Strength.Value >= 10000 then
player.de.Value = true
player.leaderstats.Strength.Value = player.leaderstats.Strength.Value + 500
wait(0.1)
player.de.Value = false
end
end)
BagEvents.E.OnServerEvent:Connect(function(player)
if player.de.Value == false and player.leaderstats.Strength.Value >= 50000 then
player.de.Value = true
player.leaderstats.Strength.Value = player.leaderstats.Strength.Value + 2500
wait(0.1)
player.de.Value = false
end
end)
Local Script (Inside the Punch Button)
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local rs = game:GetService("ReplicatedStorage")
local BagEvents = rs:WaitForChild("BagEvents")
local BagEvent1 = BagEvents:WaitForChild("A")
local BagEvent2 = BagEvents:WaitForChild("B")
local BagEvent3 = BagEvents:WaitForChild("C")
local BagEvent4 = BagEvents:WaitForChild("D")
local BagEvent5 = BagEvents:WaitForChild("E")
script.Parent.MouseButton1Up:Connect(function()
if player.CurrentBag.Value == 1 then
BagEvent1:FireServer(player)
elseif player.CurrentBag.Value == 2 then
BagEvent2:FireServer(player)
elseif player.CurrentBag.Value == 3 then
BagEvent3:FireServer(player)
elseif player.CurrentBag.Value == 4 then
BagEvent4:FireServer(player)
elseif player.CurrentBag.Value == 5 then
BagEvent5:FireServer(player)
end
end)