You’d probably need to use RemoteEvents in order to accomplish this instance, since UI Buttons can’t exactly detect server-sided input from the client & changing it from the client would not replicate across the server
Keeping in mind you have to do this through a LocalScript, for the RemoteEvent to detect client-server replication
When a button gets pressed, fire a RemoteEvent from the client to the server to change the stats the way
--Client Side
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
script.Parent.MouseButton1Click:Connect(function()
Event:FireServer()
end)
--Server Side
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
Event.OnServerEvent:Connect(function(Player) --The player is already passed as the first parameter
Player.leaderstats.Clicks.Value += 1
end)
I don’t really know lol. I think I’m confused with the difference of those. Can you help me out here? What script should be used? You don’t need to directly give me the script if you don’t want to. Just guide me on what to script. Thanks!
So in Lua, we have these things called Events which basically fire depending on what “action” you want it to detect from
Say I have this (Of course just an example):
local AppleTree = workspace.AppleTree
AppleTree.PushedDown:Connect(function()
print("I've been pushed down >:(")
end)
Since we referenced PushedDown as an event, we have to connect it with a function in order to properly detect whenever it changes
The same goes for MouseButton1Click event, that event fires whenever you click the UI Button with your “Left Mouse” which would fire a RemoteEvent (Which you can create by placing one inside ReplicatedStorage)
After that Event gets fired from the client to the server, we can then create another script to detect when it got fired from as stated from my previous post:
It may look simple, but let’s break it down
OnServerEvent would be considered an Event for detecting who called the FireServer() function, and it has 1 parameter:
The Player who fired FireServer() from our Local Side earlier (Or the MouseButton1Click event)
Then we can reference our leaderstats, and the Clicks to increase its Value by 1 hopefully!
If you’re referring about the 2 scripts that have different replication:
Then yeah, you can put the LocalScript where your UI Button is located, then the ServerScript you can create one & place it inside ServerScriptService so that it detects when FireServer() is called on the client to be able to increase the Clicks value by 1
ClickDetectors & ProximityPrompts are nifty Objects we can use that detect when a Player either Mouse Clicks/Keyboard Types, which is the more common use that people use