So, I want to know how to make a system like this: If a player touches, for example, a bloxy cola, then how do i make a text label say: “Insert username that touched the bloxy cola” has won the game!. I am a beginner coder and I need help with this system.
Do you want that text to show for all people?
Yeah, I do, I’m making some kind of round based game.
Alright, you are going to have to use .Touched to detect when a part is touched, and RemoteEvents to tell every player that you won. I’ll give you a guide since you’re a new programmer.
-
We are going to first add everything we need, and here’s the list:
RemoteEvent:
Winner GUI and LocalScript:
Script:
-
To handle collision detection, we need to use .Touched inside the server script:
--//Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--//Variables
local DisplayWinner = ReplicatedStorage.DisplayWinner
local Part = workspace.MyCoolPartName --//Change if needed
--//Functions
Part.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
DisplayWinner:FireAllClients(player.Name)
end
end)
- To display the winner, we need to receive the remote event in the LocalScript:
--//Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--//Variables
local DisplayWinner = ReplicatedStorage.DisplayWinner
local TextLabel = script.Parent
--//Functions
DisplayWinner.OnClientEvent:Connect(function(winnerName)
TextLabel.Visible = true
TextLabel.Text = winnerName .." won the game!"
task.wait(5)
TextLabel.Visible = false
end)
Thank you!, but what does “if player then
DisplayWinner:FireAllClients(player.Name)” do?
It saying if player so if its a player then
do something
It fires a RemoteEvent to every single player with the arguments player.Name. It’s similar to sending a letter to someone with the message player.Name.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.