The code for the script is identical to another script that experiences no issues. The only difference between the two is that the one that is causing problems is a Localscript whereas the other one is a Serverscript.
Why might this be happening?
Code:
local button = script.Parent
local bruh = button.bruh
local investment = script.Parent.investment.Value
local price = script.Parent.price.Value
local fixedprice = script.Parent.fixedprice.Value
local name = "Slingshot"
local team = "Red"
local class = "Tools"
button.MouseButton1Click:Connect(function()
local player = game.Players.LocalPlayer
local cash = player.leaderstats.Cash
bruh.BackgroundTransparency = 0
if (cash.Value >= 1 and investment + cash.Value < price or investment + cash.Value < fixedprice) then
investment = investment + cash.Value
cash.Value = 0
price = fixedprice - investment
local ShopColor = Color3.fromRGB(255,255,0):Lerp(Color3.fromRGB(0, 170, 0), investment/fixedprice)
bruh.BackgroundColor3 = ShopColor
bruh:TweenSize(UDim2.new(investment/fixedprice,0,1,0), "In", "Linear", 1)
button.TextLabel.Text = fixedprice-investment
else
if (cash.Value + investment >= price) then
price = fixedprice - investment
cash.Value = cash.Value - price
price = 0
investment = 250
bruh.BackgroundColor3 = Color3.fromRGB(0, 170, 0)
bruh.BackgroundTransparency = 1
button.BackgroundColor3 = Color3.fromRGB(0, 170, 0)
button.TextLabel.Text = 0
game.ReplicatedStorage.Menuevent:FireServer(team,name,class)
script.Disabled = true
end
end
end)
Yes, you would use a remote event to trigger the purchase (or whatever it is) on the server, and then either have a LocalScript listen for the changes through .Changed or through another remote event.
uhhhhhhhhh so i was trying to send cash.Value on the remote event as the player’s money, but that wasn’t working so i was trying to replace cash.Value with a variable and send that and this happens
a number value. it is just an int value that is a sibling of the local script. that is out of the quesiton because everytime i mess with the cash part the error changes
game.ReplicatedStorage.Money.OnServerEvent:Connect(function(investment,player,cash,price)
local target = game.Players:FindFirstChild(player)
local e = target.leaderstats.Cash.Value
if investment + e < price then
target.leaderstats.Cash.Value = 0
end
if investment + e >= price then
target.leaderstats.Cash.Value = target.leaderstats.Cash.Value - price
end
end)
if (cash.Value >= 1 and investment + cash.Value < price or investment + cash.Value < fixedprice) then
game.ReplicatedStorage.Money:FireServer(investment,player,cash,price)
The first argument is the player, parameter names don’t matter. So passing :FireServer(1, 2) is just the same as passing LocalPlayer, 1, 2
-- Client
Event:FireServer(1, 2)
-- Server
Event.OnServerEvent:Connect(function(player, value0, value1)
print(player, value0, value1) --> Player, 1, 2
end
So you can just do player.leaderstats.Cash.Value to get the value
Server:
game.ReplicatedStorage.Money.OnServerEvent:Connect(function(player,investment,cash,price)
local e = player.leaderstats.Cash.Value
if investment + e < price then
target.leaderstats.Cash.Value = 0
elseif investment + e >= price then
player.leaderstats.Cash.Value -= price
end
end)
Client:
if (cash.Value >= 1 and investment + cash.Value < price or investment + cash.Value < fixedprice) then
game.ReplicatedStorage.Money:FireServer(investment,cash,price)