So I have been struggling with scripting and making a GUI opening by clicking a player.
I planned that the GUI could show the badges of a player that got but sadly it didn’t make the final cut.
If someone can help me with this project I want to make it! I would be honored.
-- LocalScript in StarterCharacterScripts: PlayerClickedScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Create a RemoteEvent to communicate between client and server
local playerClickedEvent = Instance.new("RemoteEvent")
playerClickedEvent.Name = "PlayerClickedEvent"
playerClickedEvent.Parent = ReplicatedStorage
-- LocalScript in StarterCharacterScripts: PlayerClickedScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Create a RemoteEvent to communicate between client and server
local playerClickedEvent = Instance.new("RemoteEvent")
playerClickedEvent.Name = "PlayerClickedEvent"
playerClickedEvent.Parent = ReplicatedStorage
-- Define the name or identifier of the GUI to open
local guiName = "PlayerBadgeGui" -- Replace "YourGUINameHere" with the actual name of your GUI
-- Function to handle ClickDetector mouse clicks
local function onCharacterClicked()
-- Fire the RemoteEvent with the GUI name as an argument
playerClickedEvent:FireServer(guiName)
end
-- Get the local player's character
local character = game.Players.LocalPlayer.Character
-- Check if the character exists and has a humanoid
if character then
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
-- Create a ClickDetector and connect it to the onCharacterClicked function
local clickDetector = Instance.new("ClickDetector")
clickDetector.Parent = humanoid
clickDetector.MouseClick:Connect(onCharacterClicked)
end
end
-- Listen for the PlayerClickedEvent from clients
playerClickedEvent.OnServerEvent:Connect(function(player, guiName)
-- Get the GUI object by its name
local gui = player.PlayerGui:FindFirstChild(guiName)
if gui then
-- Set the visibility of the GUI to true
gui.Enabled = true
else
warn("GUI not found for player: " .. player.Name)
end
end)
i’ve made a gui, used the clickdetector and the remoteEvent