So basically I have a finish line (a no collide, transparent wall), when someone crosses this finish line a GUI should pop up telling them what place they're in. To achieve this I've used a Script to to launch a remote event when someone touches the block and a local script to make that GUI visible. My problem is getting that variable in the TextBox of the GUI. Basically I want a variable that goes up by one every time someone touches the block so that the GUI can tell someone what place they got in a race.
Here's my Script:
local debounce = false game.Workspace.FinishLine.Touched:Connect(function(hit) if not debounce then debounce = true if game.Players:GetPlayerFromCharacter(hit.Parent) then game.ReplicatedStorage.ShowGUI:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent)) end wait(2) debounce = false end end)
and here's my local script:
game.ReplicatedStorage.ShowGUI.OnClientEvent:Connect(function() script.Parent.Frame.Visible = true wait(2) script.Parent.Frame.Visible = false end)
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") --create an int value inside RS with value of 0 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) -- create a new remove event 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.