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?