I want to make a text that if you click it, it will raise one number (Ex: Number is 0, player press it and it raises one, but he can't click again) and it will sync to all servers, i know there is a way to make that "sycn" can someone explain it?
COMMUNITY QUESTION
How can i make an button that if you press will add one point to the text?
2 answers
Here is a way to do it using remoteFunctions.
You will create the remotefunction on the server with a certain name, then get it on the client in a localscript. Then you call it; when the server receives the call request, it checks if it's already been called. If so, it does nothing, but if this call is the first, it takes action.
The server returns the status of the call.
in a modulescript in serverScriptStorage:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local clickRequest = Instance.new("RemoteFunction")
clickRequest.Parent = ReplicatedStorage
clickRequest.Name = "ClickRequest "
local hasBeenIncremented = false
local count = 0
local incrementerUserId = nil
local function onClickRequest (player)
print(player.Name, "wants to increment the number")
if hasBeenIncremented then
return false --it has already been incremented by someone else
end
--actually increment the number
incrementerUserId = player.UserId
hasBeenIncremented=true
count = count + 1
--take other actions which you want to sync to servers - updating physical world, sending messages etc.
return true
end
clickRequest .OnServerInvoke = onClickRequest Requested
in a localscript inside the player object
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local clickRequest = ReplicatedStorage:WaitForChild("ClickRequest ")
local IWasFirst = clickRequest:InvokeServer()
print("I tried to click; was I first?"..tostring(IWasFirst))
game.somewhere.MouseButton1Click:connect(function() some variable = variable + number end) Then self destruct the point script.
This discussion is preserved as it was. New answers, comments, and votes are closed.
