"Unable to cast value to object"

Here’s the script :

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
image

what’s the manager module doing and at what line does this occur? this pretty much just means that it’s receiving the multiplier in an unexpected way

Here’s the manager script

	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

On what line is this exactly happening?

i… dont know…
it just sends an error saying this
image

What is oremultiplier? is oremultiplier a NumberValue? maybe try

oremultiplier.Value = math.random(1.1, 2)

The blue text underneath that should be a error trace, including the line numbers.

image

Just send the whole output, not just a crop of it

no it isn’t but even if i delete the oremultiplier thing it still doesn’t work

yes! keep going! almost there! you can also copy the text instead of using a screenshot!

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

Which one is the Health Script? The first or second script

so it’s happening in your Rock.Health.Script at line 39. can you show us that script and point out which line is #39?

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)

game:GetService("ReplicatedStorage").RockDestroyed:FireClient(player)

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

what is script.Parent in that case?

it’s a number value
(char limit)