Remote event returning player instead of number?

You are passing the reference to that object to FindFirstChild(), which means it will look for that exact object. You need to pass the name, script.Parent.Title.Name

It’s searching from the text value, the title is a textlabel, ill change it to the name of the textlabels parent, thats a bit better i think.

Because the text and name is the same.

1 Like

Are you sure that the name of that number value you are looking for is the same as the text in the text label? Also, be careful with tonumber(), because if the target text thing isn’t a number, it’ll become nil:

1 Like

Oh wait i fixed it for real this time!
The thing its sending is an instance, it needs to be target.Value!
This is just one of those cases where i misread everything and mess it up.
I’m sorry and thanks for your patience!

1 Like

Final Code:

Client:

script.Parent.InputBegan:Connect(function(obj)
	if obj.UserInputType == Enum.UserInputType.MouseButton1 then
		local target = game.Players.LocalPlayer.Inventory:FindFirstChild(script.Parent.Name)
		game.ReplicatedStorage.AddMoney:FireServer(target.Value)
		target:Destroy()
		script.Parent:Destroy()
	end
end)

Server code: (only important part)

game.ReplicatedStorage.AddMoney.OnServerEvent:Connect(function(plr,money)
	plr.leaderstats.Money.Value = plr.leaderstats.Money.Value + money
	local ui = Instance.new("ScreenGui")
	ui.Parent = plr.PlayerGui
	local text = Instance.new("TextLabel")
	text.TextColor3 = Color3.fromRGB(108, 255, 82)
	text.TextScaled = true
	text.Font = Enum.Font.FredokaOne
	text.BackgroundTransparency = 1
	text.Position = UDim2.new(math.random(1,10)/10,0,1,0)
	text.Parent = ui
	text.Text = "+"..money
	text.Size = UDim2.new(0, 200,0, 50)
	local tweenp = game:GetService("TweenService"):Create(text,TweenInfo.new(2,Enum.EasingStyle.Sine),{Position = UDim2.new(text.Position.X,0,0.5,0)})
	local tweent = game:GetService("TweenService"):Create(text,TweenInfo.new(2,Enum.EasingStyle.Linear),{TextTransparency = 1})
	tweenp:Play()
	tweent:Play()
	game:GetService("Debris"):AddItem(ui,2)
end)
1 Like

The number value’s value… is a number, no need to convert it. Also, BIG THING: why is your client telling the server what to do? Exploiters can just send ANY value through the function, and… your server will give them as much money as they want.

1 Like

First why to convert it:
I just misread it, it happens.

Secondly:
How else would i be able to detect a button press and send money to leaderstats all from the client? Then the money would be clientsided an not show up.

1 Like

Is the button press always increasing the player’s leaderstat value by a fixed number, one the server knows? Then you should only have the client tell the server that they pressed the button, and the server should increase their leaderstat by THAT value. Additionally, if there’s some other conditions, like if the player has to be close to something to press that button, do a sanity check on the server to see if they are close to where they need to be.

1 Like

It’s not a fixed number, its the value of an ingame item to sell to an npc for ingame currency.

The server can access the number value, since it’s in a player object, right? So, when the client presses the button, it should fire the event. Then the server should get that value, and add it to the player’s leaderstat.

But only the client knows what to sell. The server doesn’t.

Then have the client tell the server what it wants to sell. Pass script.Parent.Name to the server and let it get the value and handle increasing the leaderstats.

Yeah, but what’s the point of that tough? It’s working fine right now.

The server can check if what the client is trying to sell exists, and also if there’s more than 0 of it, to sell.

True. But, if I was an exploiter, I could tell the server whatever I want and make it give me infinite money. This would be VERY easy to do. And also very easy to fix. I highly recommend you add these sanity checks so that you don’t have to worry about it later.

For example, if the client is trying to sell wood, they should pass the name of the number value in their inventory, “wood”

Check (on the server):

  • if there even exists a number value named “wood” in the player’s inventory

  • check if they have more than 0 wood, you wouldn’t want it to go into the negatives

  • if the client tells you how much wood they want to sell, make sure it’s not more than what they actually have

  • after the checks, decrease the amount of wood they have, and increase their leaderstat

1 Like