Passing information from server to client not working

I am currently working on a way to pass a number value from server to client, but I get this error whenever I start testing it.

image

I am using this a simple block breaking system that I am working on just for fun and to sharpen my skills, so the code is very messy.

Code:

local event = game:GetService("ReplicatedStorage").BlockHpEvent

for i,v in ipairs(workspace:GetDescendants()) do
	if v:IsA("Part") then
		for i,v in ipairs(v:GetDescendants()) do
			if v:IsA("NumberValue") then
				if v.Name == "Strength" then
					v.Parent.ClickDetector.MouseClick:Connect(function()
						v.Value -= 2
						if v.Value < 1 then
							v.Parent.Parent = game:GetService("ReplicatedStorage").DeletedParts
						end
					end)
					
					v.Parent.ClickDetector.MouseHoverEnter:Connect(function()
						local BlockHp = v.Value
						event:FireClient(BlockHp)
						
						local selBox = Instance.new("SelectionBox")
						
						local color = v.Parent.Color
						local r, g, b = 0,0,0
						
						r = 255 - (color.R*255)
						g = 255 - (color.G*255)
						b = 255 - (color.B*255)
						
						selBox.Color3 = Color3.fromRGB(r,g,b)
						selBox.Adornee = v.Parent
						selBox.Name = "selBox"
						selBox.Parent = v.Parent
						
					end)
					
					v.Parent.ClickDetector.MouseHoverLeave:Connect(function()
						for i,v in ipairs(v.Parent:GetDescendants()) do
							if v:IsA("SelectionBox") then
								if v.Name == "selBox" then
									v:Destroy()
								end
							end
						end
					end)
				end
			end
		end
	end
end

The part that is having the error is this:

local BlockHp = v.Value
event:FireClient(BlockHp)

I have never passed information from server to client, I have done client to server, but they should be the same so I don’t know why this is happening.

Oh yeah, here is the client script, if you catch any error please say.

local event = game:GetService("ReplicatedStorage").BlockHpEvent
local plr = game.Players.LocalPlayer

game.ReplicatedStorage.BlockHpEvent.OnClientEvent:Connect(function(plr,BlockHp)
	script.Parent.Visible = true
	while wait() do
		script.Parent.BlockHpLabel.Text = BlockHp
		
		if BlockHp < 1 then
			script.Parent.Visible = false
		end
	end
end)

Any help would be appreciated!

game.ReplicatedStorage.BlockHpEvent.OnClientEvent:Connect(function(plr,BlockHp)
take out plr. See if that works.

2 Likes

You need to specify the player to fire the event to here…

1 Like

This aswell my bad didn’t read first script.

1 Like

LocalPlayer

local player = game.Players.LocalPlayer
1 Like

How should I get the player though?

It’s in the local script. if you’re firing to client from a server script. The server script needs to find the client it’s firing being that Player which you have no client in the :FireClient() function. And the local script doesn’t need a plr because it can find the player by localplayer.

2 Likes

This function is passed the player, you just need to accept it.

v.Parent.ClickDetector.MouseHoverEnter:Connect(function(player)

1 Like

That worked, but now there is another error in the local script:

image

The gui appears without doing anything.

Did you remove the plr part in the local script?

1 Like

that worked, but this just happens:

Also, I need to go to bed very soon, so I might have to continue this tomorrow.

Don’t mind the different account.

To be honest I believe it’s breaking due to the fact that you have a while wait() do in the event. Try removing that line and see if that works.

1 Like

I was wrong, It doesn’t update when you click on a part, lowering the hp of the part. I have to go to bed like right now, so I might have to respond to you tomorrow.

Hey so I tried to find a way to make the count update live, because if you click on a block, the count will stay the same until you stop hovering over the block, and then hover over it again. Do you know a solution to this? Because I don’t, I tried .Changed, and of course, it only works with instances, not parameters. I don’t know what else to try, I originally did the While wait(1) do so it could update, but that caused another problem.

Do you want the value to only update for the player that clicked? If so, just fire the event from the click function to update the player with the value. If you want other players that might be hovering to also update, you will want to add a table to keep track of all players that are currently hovering the part and fire the event for each of them when the click is detected and the value is reduced.

You shouldn’t use remotes for that. I see you have numbervalue in object, so you can handle everything on client.

1 Like