First, if you want to make a value/variable in client, don't do it! Your client can manipulate the value and this is not good if your game has a reward system.
So you want to use Remote Function
Basically, in your server script above you just want to change Remote Events to Remote Functions.
You want to create an int value inside ReplicatedStorage since it's the much more safer than using value inside the client.
Main Variable:
(1) ShowGUI ( Remote Function inside RS )
(2) ShowRanking ( Remote Events inside RS )
(3) Placement ( Int Value inside RS )
local RS = game:GetService("ReplicatedStorage")
local Rank = RS:WaitForChild("Placement")
local debounce = false
game.Workspace.FinishLine.Touched:Connect(function(hit)
if not debounce then
debounce = true
if game.Players:GetPlayerFromCharacter(hit.Parent) then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local Result = game.ReplicatedStorage.ShowGUI:InvokeClient(player))
end
end
wait(.25)
debounce = false
end)
Now in your local script, you want to pick up the information from the server and then return a boolean value
local Event = game:GetService("ReplicatedStorage").ShowGUI
Event.OnClientInvoke = function()
return true
end
After that basically the server will get the result of true. Simply say this inside your server script under Result Variable
if Result == true then
Rank.Value = Rank.Value + 1
game.ReplicatedStorage.ShowRanking:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent), Rank.Value)
end
Then, the client will pick it up again and you are ready to go, simply set the text to whatever you want, I'll give an example:
game.ReplicatedStorage.ShowRanking.OnClientEvent:Connect(function(playerRank)
local rank = tonumber(playerRank)
print(rank)
script.Parent.Visible = true
if rank == 1 then
script.Parent.Text = "You are " .. rank .. "st!"
elseif rank == 2 then
script.Parent.Text = "You are " .. rank .. "nd!"
elseif rank == 3 then
script.Parent.Text = "You are " .. rank .. "rd!"
else
script.Parent.Text = "You are " .. rank .. "th!"
end
wait(2)
script.Parent.Visible = false
end)
I hope this is what you are looking for.
5 comments
Are you trying to make the ui pop up to everyone or just a single person?
Just a single person. So the first person would touch the block and only they would get the message saying "You're 1st" and the second person to touch the block would get the pop up "You're 2nd" when they touch the block. But I need the placement variable to go up by one each time so everyone gets the right placement number.
I think it's better to use Remote Function, because you can communicate between Server-Client-Server!
Alright, I did look into that a bit, and figured it could be the solution. If I went that route could I then create a function in one script that only applies to a local player?
Yeah I think you can