Hello. I am currently making a game that involves people getting first, second, or third. Currently, I have it when the first person touches the finishing platform, it sets a winning value to their name. But, I want to make it so that when another person touches the platform (the one who got second) sets the secondplace value to their name and same thing for when the third person touches the platform. Here is my script so far:
Do not mind the script involving the GUI. The values I have are located in Replicated Storage in a folder called βValues.β The values are called WinnerValue, SecondPlace, and ThirdPlace. Thank you for reading! If I didnβt explain anything correctly or if something needs an explanation, please ask.
if game.ReplicatedStorage.Values.WinnerValue.Value == nil then-- checks if no one has hit the finish line
game.ReplicatedStorage.Values.WinnerValue.Value == hit.Parent.Name
elseif game.ReplicatedStorage.Values.SecondWinnerValue.Value == nil then--checks if any second person has hit the end
game.ReplicatedStorage.Values.SecondWinnerValue.Value = hit.Parent.Name
elseif game.ReplicatedStorage.Values.ThirdWinnerValue.Value == nil then
game.ReplicatedStorage.Values.ThirdWinnerValue.Value
end
This just bassically goes from first to thrid, if a player finishes and someone has already finished they will be saved as second place. though if someone touches the finish twice, it will cause them to possibly be in first and second or second and thrid, this can just be solved by checking if the player hasnβt already been saved into a value
script.Parent.Touched:Connect(function(hit)
local hum = hit.Parent:FindFirstChild("Humanoid")
if game.ReplicatedStorage.Values.WinnerValue.Value == nil then-- checks if no one has hit the finish line
game.ReplicatedStorage.Values.WinnerValue.Value = hit.Parent.Name
elseif game.ReplicatedStorage.Values.SecondPlace.Value == nil then--checks if any second person has hit the end
game.ReplicatedStorage.Values.SecondPlace.Value = hit.Parent.Name
elseif game.ReplicatedStorage.Values.ThirdPlace.Value == nil then
game.ReplicatedStorage.Values.ThirdPlace.Value = hit.Parent.Name
end
end)
I made all the necessary changes to fit the variable names and fixed the extra β=β in the 2nd and fourth line of your script but it does not seem to be working. There are no errors noted in the output so I do not know what is wrong.
--//Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--//Variables
local Part = script.Parent
--//Functions
Part.Touched:Connect(function(hit)
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
if Humanoid then
if ReplicatedStorage.Values.WinnerValue.Value == nil then
ReplicatedStorage.Values.WinnerValue.Value = hit.Parent.Name
elseif ReplicatedStorage.Values.SecondPlace.Value == nil then
ReplicatedStorage.Values.SecondPlace.Value = hit.Parent.Name
elseif ReplicatedStorage.Values.ThirdPlace.Value == nil then
ReplicatedStorage.Values.ThirdPlace.Value = hit.Parent.Name
end
end
end)
Weird. This script doesnβt seem to work either. I made a clean baseplate with a part and three values in a folder called βValuesβ located in ReplicatedStorage but the script doesnβt work there either.
script.Parent.Touched:Connect(function(hit)
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum then
if game.ReplicatedStorage.Values.WinnerValue.Value == nil then-- checks if no one has hit the finish line
game.ReplicatedStorage.Values.WinnerValue.Value = hit.Parent.Name
elseif game.ReplicatedStorage.Values.SecondPlace.Value == nil then--checks if any second person has hit the end
game.ReplicatedStorage.Values.SecondPlace.Value = hit.Parent.Name
elseif game.ReplicatedStorage.Values.ThirdPlace.Value == nil then
game.ReplicatedStorage.Values.ThirdPlace.Value = hit.Parent.Name
end
end
end)
Also you should show me the scripts for the GUI so I can fix your problem if the above code doesnβt work. If it worked it please set it as the solution Thanks!
This script does not work either and I am using a brandnew baseplate to make sure their are no outside processes affecting it. I donβt seem to know why it is not working. So basically what I am trying to do, is when the 1st, 2nd, 3rd person touch the platform, their names go to the specific values. Those values are then used after the round is over to show who won on a GUI by the values being linked to a label.
So really, im trying to get the values = to what place each person got so it can be shown on the GUI. If you need any more explanation, just ask.
what do you mean βtested in the serverβ ? Because you are using a server script to change the value so you should look at the value rom the server side
I have been looking at the value in Studio using the explorer and keeping the properties of the value open. I misworded the last thing I said. Regardless, the value is not changing and there are no errors shown in the output.
script.Parent.Touched:Connect(function(hit)
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum then
if game.ReplicatedStorage.Values.WinnerValue.Value == nil then-- checks if no one has hit the finish line
game.ReplicatedStorage.Values.WinnerValue.Value = hit.Parent.Name
print("A")
elseif game.ReplicatedStorage.Values.SecondPlace.Value == nil then--checks if any second person has hit the end
game.ReplicatedStorage.Values.SecondPlace.Value = hit.Parent.Name
print("B")
elseif game.ReplicatedStorage.Values.ThirdPlace.Value == nil then
game.ReplicatedStorage.Values.ThirdPlace.Value = hit.Parent.Name
print("C")
end
end
end)
This is the code, and the benefit to this is that you can get everyoneβs rank, so I think this is just better.
local Values = game.ReplicatedStorage:WaitForChild("Values");
local FinishedPlayers = {}; --All the players who touched the FinishPart will be added to this list in order.
FinishPart.Touched:Connect(function(Hit)
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent); --Get the player.
if Player then --If the player exist then continue.
local Rank = (#FinishedPlayers + 1); --Get the rank.
FinishedPlayers[Rank] = Player; --Add the player to the list.
if Rank == 1 then
Values.FirstPlace.Value = Player.Name; --Or Player.DisplayName;
elseif Rank == 2 then
Values.SecondPlace.Value = Player.Name; --Or Player.DisplayName;
elseif Rank == 3 then
Values.ThirdPlace.Value = Player.Name; --Or Player.DisplayName;
end
end
end)