So basically i am trying to make a game with pets that have individual damage values in them. However, i want those damage values in each pet add up to a total number, which would be the damage output. This would only happen if the player has multiple pets equipped. Any ideas on how to do this?
Script:
local rS = game:GetService("RunService")
local RS = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
local drops = workspace.MainFolder_Workspace.Drops
local remotes = RS:WaitForChild("Remotes")
local FolderCreate = remotes.FolderCreate
local mainSS = player:WaitForChild("PlayerGui"):WaitForChild("MainSS")
local doorPurchaseUI = mainSS:WaitForChild("PurchaseArea")
local DDs = RS:WaitForChild("DespawnedDrops")
local PPs = workspace.MainFolder_Workspace.PlayerPets
local areaBuyBtnConnection
local function destroyDrop(drop)
task.wait(0.5)
local oldParent = drop.Parent
drop.Parent = DDs
task.wait(5)
drop.Health.Value = drop.MaxHealth.Value
drop.Parent = oldParent
end
remotes.PromptPurchaseDoor.OnClientEvent:Connect(function(door)
doorPurchaseUI.Visible = true
doorPurchaseUI.PurchaseText.Text = "Would you like to purchase this area this area for "..door.Price.Value.." ECoins?"
areaBuyBtnConnection = doorPurchaseUI.Buy.MouseButton1Click:Connect(function()
local result = remotes.PurchaseDoor:InvokeServer(door)
if result == true then
door:Destroy()
end
areaBuyBtnConnection:Disconnect()
doorPurchaseUI.Visible = false
end)
end)
doorPurchaseUI.Close.MouseButton1Click:Connect(function()
doorPurchaseUI.Visible = false
end)
for _, drop in pairs(drops:GetDescendants()) do
if drop:IsA("Model") then
drop.Health.Value = drop.MaxHealth.Value
drop.ClickDetector.MouseClick:Connect(function(player)
local CPPs = PPs[player.Name]
if #CPPs:GetChildren() > 0 then
local pet = CPPs:FindFirstChildOfClass("Model")
if player.Values.SentTo.Value == nil then
player.Values.SentTo.Value = drop
pet.Attack.Value = player.Values.SentTo.Value
elseif player.Values.SentTo.Value == drop then
player.Values.SentTo.Value = nil
pet.Attack.Value = player.Values.SentTo.Value
elseif player.Values.SentTo.Value ~= nil and player.Values.SentTo.Value ~= drop then
player.Values.SentTo.Value = drop
pet.Attack.Value = player.Values.SentTo.Value
end
end
end)
end
end
task.spawn(function()
while wait(1) do
if player.Values.SentTo.Value ~= nil then
local CPPs = PPs[player.Name]
if #CPPs:GetChildren() > 0 then
if #CPPs:GetChildren() >= 2 then
local TD = player.Values.TotalDamage
TD.Value = ...
local pet = CPPs:FindFirstChildOfClass("Model")
local dmg = pet.Damage.Value * #CPPs:GetChildren()
player.Values.SentTo.Value.Health.Value = math.max(player.Values.SentTo.Value.Health.Value - dmg, 0)
if player.Values.SentTo.Value.Health.Value == 0 then
remotes.StopDamaging:FireServer()
destroyDrop(player.Values.SentTo.Value)
end
elseif #CPPs:GetChildren() == 1 then
local pet = CPPs:FindFirstChildOfClass("Model")
local dmg = pet.Damage.Value
player.Values.SentTo.Value.Health.Value = math.max(player.Values.SentTo.Value.Health.Value - dmg, 0)
if player.Values.SentTo.Value.Health.Value == 0 then
remotes.StopDamaging:FireServer()
destroyDrop(player.Values.SentTo.Value)
end
end
end
end
end
end)
rS.Heartbeat:Connect(function()
for _, drop in pairs(workspace:WaitForChild("MainFolder_Workspace"):WaitForChild("Drops"):GetDescendants()) do
if drop:IsA("Model") then
local hD = drop:FindFirstChild("HealthDisplay")
local bar = hD.Background.Bar
local hDT = hD.Background.HealthDisplayLabel
hDT.Text = drop.Health.Value
bar:TweenSize(UDim2.fromScale(drop.Health.Value/drop.MaxHealth.Value, 1), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.3)
end
end
end)
Example of the Pet: