RemoteEvent telling server script wrong values

I am trying to get the RemoteEvent to tell the correct values to the server script.

When the “Buy” RemoteEvent is triggered the values that it is supposed to send to the server script are not being sent.

I’ve tried using print statements in both scripts to confirm the variables were correct and they were. I’m not sure how they could be getting messed up.

LocalScript: (I add anticheat at the end)

local Player = game.Players.LocalPlayer

local Items = script.Parent.ScrollingFrame
local BuyFrame = script.Parent.BuyFrame

Items.NerfedGravityCoil.ImageButton.MouseButton1Click:Connect(function()
	BuyFrame.Visible = true
	BuyFrame.ImageLabel.Image = Items.NerfedGravityCoil.ImageButton.Image
	BuyFrame.Title.Text = Items.NerfedGravityCoil.ItemName.Text
	BuyFrame.Cost.Text = "Cost: " .. tostring(Items.NerfedGravityCoil.Cost.Value)
end)

BuyFrame.Buy.MouseButton1Click:Connect(function()
	local Item = BuyFrame.Title.Text
	
	local separator = " "
	local array = string.split(BuyFrame.Cost.Text, separator)
	
	local Cost
	for i,v in array do
		if tonumber(v) ~= nil then
			Cost = tonumber(v)
		end
	end
	print(Cost)
	print(Item)
	game.ReplicatedStorage.Remotes.Buy:FireServer(Player, Item, Cost)
end)

Server Script:

local Items = game.Lighting.Shop

game.ReplicatedStorage.Remotes.Buy.OnServerEvent:Connect(function(Player, Item, Cost)
	print(Item)
	print(Cost)
	Player.leaderstats.Karma.Value -= tonumber(Cost)
	Items[Item].Parent = game.Players[Player].Backpack
end)

In short, why is the RemoteEvent telling the server script incorrect values and how can I fix this issue?

When firing to the server, you don’t need to add the Player instance into the parameters. Just do game.ReplicatedStorage.Remotes.Buy:FireServer(Item, Cost)

2 Likes

How do I call the player in the server script with no variable for the player?

The first argument in a remoteevent is always the player, and then the values you gave it.

2 Likes

Additionally, you can learn more about RemoteEvents here: RemoteEvent | Roblox Creator Documentation

2 Likes

So I shouldn’t change the server script at all, only remove Player from the last line of the LocalScript?

1 Like

Correct! It should work by removing the player instance from the local server, and keeping everything else the same

2 Likes

Thanks a lot. The script is now working. :grinning:

1 Like

You’d only need to do that for :FireClient()

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.