So I have 2 options
1: Create 12 Remote Events for the 12 tools
2:Do that thing that dont know how to do
What do you recomment?
I would recommend my way, because it cuts back on a lot of extra code that you would have with 12 remote events. All you will need to do is copy and paste the MouseButton1Click function you already have, and just change the button name, cost value, and item name
And wich function is that? is the one of the buy button?
You don’t want to mess with the OnServerEvent function at all. You want to copy and paste the MouseButton1Click function for as many buttons in the shop you have, and change the two parameters inside of it. The first is the value, so change that to how much you want it to cost, and the second parameter is the name of the tool you are buying. And you want to change which button you are clicking. For example, you are using script.Parent, but you will want you to change that to wherever the other button is. If you want to keep using script.Parent, just clone the local script into every button.
But I copy them on a script on the frame of the ScreenGUI or in the ScreenGui directly? Because I have a local script insade every button on the shop and that didn’t gave the powers to the tools
So, you already have a script inside of every button? If so, thats good. Then you only need to change the server script so that it only looks likes this.
RemoteEvent.OnServerEvent:Connect(function(player, Value, Item) --
player.leaderstats.Points.Value = player.leaderstats.Points.Value - Value
game.ReplicatedStorage.Library[Item]:Clone().Parent = player:WaitForChild("Backpack")
end)
Then everything should work. And if you haven’t already change the arguments in FireServer() so that they represent the amount you want taken away, and the tool you want to give
So I have to change the item on:
game.ReplicatedStorage.Library[Item]
or not? Because if I have to, I will have to create the remote events and if I have not to do that, lua wornt know what item should give you.
Item is being passed by the FireServer(), just like Value is. You need to change the string that is being passed by FireServer(), and that is all. [Item]
looking like that is just a way to index a variable.
The FireServer() is the one of the buybutton and I have it like this
script.Parent.MouseButton1Click:Connect(function(click)
if player.leaderstats.Points.Value >= 400 then
RemoteEvent:FireServer(400)
end
end)
It should look like this (at least the FireServer part)
RemoteEvent:FireServer(900, "DualMegaCoil")
The second argument is what you change to whatever tool you want them to get
Ok I have just understood everything watching the buybutton script. The remote event is the connection between both scripts and one script send the info to the remote event to the other
I hope it works
local player = game:GetService("Players").LocalPlayer
local RemoteEvent = game.ReplicatedStorage.RemoteEvent
script.Parent.MouseButton1Click:Connect(function(click)
if player.leaderstats.Points.Value >= 400 then
RemoteEvent:FireServer(400, "AGodSword")
end
end)
Look something like this with everyone right?
Yep. And when you edit all of them, all you change is the “400” and “AGodSword”
I followed your steps and it worked perfectly! The only problem is that when I’m buying something, It substract lot of money. for example
I had 1600 Points, I bought a 400 Points tool and the system substact me almost all the money
Do you know what is the problem?
As everyone else was saying you need to make a remote event do it only the server can handle datastores and if you change something in a local script the server does not see that change.
I have the remote event that connect the server script with the local script and everything works fine. BUt the problem is with the currency
I mean, the only way this is happening is if you didn’t change the value that it is meant to take away
Which value are you talking abut? is on the buy button?
Yeah. Did you change both the value to check if they have enough, and the cost?
script.Parent.MouseButton1Click:Connect(function(click)
if player.leaderstats.Points.Value >= 400 then
RemoteEvent:FireServer(400, "SpeedCoil")
end
end)
All of them are like this