yep it should look like that
[30 char]
why there’s a red line under value? btw sorry if i am wasting your time
Oh, you can just include a “local” before “Value” if you desire. It will still run fine even if you don’t.
when i buy something the money don’t decrerase :I
Are there any errors in the output, and are you buying the specific one that you scripted?
maybe i found the issue. i will reply if i found it
alright. just tell me if it’s right.
Value = Value - player.PlayerGui.Shop.Frame.ScrollingFrame.Cost.Value
Yep that is right. Just make sure that the value is set to what you want it to subtract
here’s a video
Ah, so their’s two problems here.
- The cost value is not changing for the GUI in the startergui
- The value is changing client side(I assume) and the server still thinks it is 0.
Local script
local player = game.Players.LocalPlayer
local button = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
button.MouseButton1Click:Connect(function()
remoteEvent:FireServer(player.PlayerGui.Shop.Frame.ScrollingFrame.Cost.Value)
end)
Server script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
remoteEvent.OnServerEvent:Connect(function(player,Cost)
Value = player.leaderstats.Coins.Value
Value = Value - Cost
end)
What this does is it passes the amount the item costs from the client to the server. The server then uses that value to subtract from the player’s value
should i only copy and paste? or change something?
You can just copy and paste it. I had to edit to clarify where you paste each one into
in the server script how does the game know what cost is? sorry if i’m asking these things but i’m new : P
The local script is passing the value to the server script. In the video you showed, the local script only knows that it costs 12 coins, because when you clicked on an item, it changed the value locally. The thing in the FireServer parenthesis is the cost of the item. The server script then takes it, and then subtracts it from the player’s coins
soo is this normal?
Oh! My bad. I messed up while pasting and editing the code. I have edited it now, so you can go ahead and change it
local script
server script
Yep, that should work as intended!
i will do a video video video video. should i go in a team test server?
i don’t understand