local rd2 = rs.RockDestroyed2
local player = game.Players.LocalPlayer
local sss = script.Parent
local pd = sss.PlayerData
local data = pd.Data
local manager = require(pd.Manager)
local function rockdestroyed(player: Player)
manager.AdjustOre(player, 10*oremultiplier)
oremultiplier = math.random(1.1, 2)
print("rock destroyed")
end
rd2.OnServerEvent:Connect(rockdestroyed)
I made another function with the exact same thing and it works, but for some reason, this function doesn’t work and it made an error
local Manager = {}
local addedmoney
local currentmoney
local addedvalue = workspace.AddedMoney
Manager.Profiles = {} --profile, storing data
function Manager.AdjustOre(player: Player, amount: number)
local profile = Manager.Profiles[player]
if not profile then return end
profile.Data.Ores += amount
player.leaderstats.Ore.Value = profile.Data.Ores
end
local player = game.Players.LocalPlayer
local sss = script.Parent
local pd = sss.PlayerData
local data = pd.Data
local manager = require(pd.Manager)
local rs = game:GetService("ReplicatedStorage")
local oreevent = rs.GetOre
local oremultiplier = math.random(1,2)
local pickstrength = require(pd.Pickaxe)
local wpick = pickstrength.woodpick
local sc = rs.ServerConnector
local sell = rs.Sell
local rd2 = rs.RockDestroyed2
local function addore(player: Player)
manager.AdjustOre(player, 1*oremultiplier)
oremultiplier = math.random(1.1, 2)
print("success")
end
local function rockdestroyed(player: Player)
manager.AdjustOre(player, 10*oremultiplier)
oremultiplier = math.random(1.1, 2)
print("success")
end
local function sellore(player: Player)
manager.SellOre(player, 0.1)
print("sold")
end
sc.OnServerEvent:Connect(addore)
sell.OnServerEvent:Connect(sellore)
rd2.OnServerEvent:Connect(rockdestroyed)
local Manager = {}
local addedmoney
local currentmoney
local addedvalue = workspace.AddedMoney
Manager.Profiles = {} --profile, storing data
function Manager.AdjustOre(player: Player, amount: number)
local profile = Manager.Profiles[player]
if not profile then return end
profile.Data.Ores += amount
player.leaderstats.Ore.Value = profile.Data.Ores
end
function Manager.buy(player: Player, amount: number)
local profile = Manager.Profiles[player]
if not profile then return end
if profile.Data.Money == amount or profile.Data.Money > amount then
profile.Data.Money -= amount
player.leaderstats.Money.Value = profile.Data.Money
end
end
function Manager.AdjustMoney(player: Player, amount: number)
local profile = Manager.Profiles[player]
if not profile then
return
end
profile.Data.Money = math.max(profile.Data.Money + amount, 0)
player.leaderstats.Money.Value = profile.Data.Money
end
function Manager.SellOre(player: Player, Multiplier: number)
local profile = Manager.Profiles[player]
if not profile then return end
currentmoney = profile.Data.Money
profile.Data.Money += profile.Data.Ores*Multiplier
profile.Data.Ores = 0
player.leaderstats.Money.Value = profile.Data.Money
player.leaderstats.Ore.Value = profile.Data.Ores
addedmoney = profile.Data.Money - currentmoney
addedvalue.Value = addedmoney
print(addedmoney)
print(addedvalue.Value)
end
return Manager
i dont think its the health script because it works fine but… here it is
local replicatedstorage = game:GetService("ReplicatedStorage")
local mining = replicatedstorage.Mining
local health = script.Parent
local pickstrength = replicatedstorage.Tool.CurrentPickaxe.Value
local dc = replicatedstorage.DisableControl
local dc2 = replicatedstorage.dc2
local strength = game:GetService("ReplicatedStorage").Tool.CurrentPickaxe.Value
local currentpickaxe = game:GetService("ReplicatedStorage").Tool.CurrentPickaxe
local cs = game:GetService("ReplicatedStorage").ChangeStrength
local cs2 = game:GetService("ReplicatedStorage").ChangeStrength2
local bgui = script.Parent.Parent.Hitbox.Part.BillboardGui
local text = bgui.TextLabel
local maxhealth = 5
cs.OnServerEvent:Connect(function()
return
end)
currentpickaxe.Changed:Connect(function()
strength = currentpickaxe.Value
print("strength changed to "..strength)
end)
mining.OnServerEvent:Connect(function()
health.Value -= strength
print("-"..strength.. " rock health")
end)
dc2.OnServerEvent:Connect(function(player)
dc:FireClient(player)
end)
script.Parent.Changed:Connect(function(player)
print("current health: ".. health.Value)
text.Text = script.Parent.Value.."/"..maxhealth
if health.Value == 0 or health.Value < 1 then
script.Parent.Parent:Destroy()
print("destroy rock")
game:GetService("ReplicatedStorage").RockDestroyed:FireClient(player)
end
end)
so i used a remote event to fire to the client and another remote event to fire to the server again… because i don’t really know how to connect server scripts to each other