(Please tell me if I should move this to #help-and-feedback:code-review )
Alright I have a confusing situation. I can get on my laptop tomorrow (Monday), but I won’t be able to login to my Devforum account during the week and if I have any bugs I’ll be able to check this post (logged out) and see the replies so anyways I’m posting this in advanced because I won’t be able to login for a while.
I’m making a Training Center for a group and because it it kind of easyish to rank up in the group and I don’t want anyone to cause harm to it I want a Pre-Made Announcement System so once you start the training you need to log your Username and TrainerID (Or something like that) then it’ll send a Discord webhook to the Discord so the owner will know that the person started a training (1. I can do this part. 2. At the end they will have to press and “End Training” button that sends a Dismissal Message and logs that the training was ended so they didn’t join then leave then join then leave so I’d think they were active.
Then the part I’m scared about bugs and I’m sure I didn’t code correctly is next.
The trainer will press a button that says “Training Intro” then I want it to play a Pre-Made announcement, but I use a Remote Event for it that fires when they press the button. The code:
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local remoteEvent = ReplicatedStorage:WaitForChild(“PreMadeIntro”)
– Announce Function
local function Announce()
game.StarterGUI.IntroGUI.Frame.Visible = true
end
– Fires Function
remoteEvent.OnServerEvent:Connect(Announce)
Then in a local script I have the FireServer() that fires after a MouseButtonClick thingy
You actually changed the GUI in StarterGui, which is wrong, you need to do it in the PlayerGui.
local plr = game.Players.LocalPlayer
local PlayerGui = plr:WaitForChild("PlayerGui")--.PlayerGui
--Note: The "LocalPlayer" can only be accessed via LocalScripts, if you use an ServerScript, it will more likely not work/bug.
And i honestly think it will fire for all players/clients, if not, use :FireAllClients() instead.
So I need to fire an event to the server that fires and event to all clients? If you don’t mind telling me, how would that work? In the local script so far I would do :FireServer() then I would :FireAllClients() when the server is fired, but in a ServerScript (Script in game.ServerScriptService)
Yes, but as I said in the post I cannot use the Devforum during the week and tomorrow (Monday) I’ll be able to use my Laptop. It is a confusing situation though.
There, when you have access to the studio, try using this code.
-- LocalScript in StarterPlayerScripts.(Under StarterPlayer.)
local remoteEvent = ReplicatedStorage:WaitForChild(“PreMadeIntro”)
game.Players.PlayerAdded:Connect(function(plr)--Fires whenever an player is added to the game.
player = plr-- Probably bad practice.(Global variable with an player instance stored.)
end)
– Fires Function
remoteEvent.OnClientEvent:Connect(function()--Fires whenever the remoteEvent is fired to an client.
player:WaitForChild("PlayerGui").IntroGUI.Frame.Visible = true
end)
--ServerScript in ServerScriptService.
local Button = ButtonYouWantPressed
if Button:FindFirstChildWhichIsA("ClickDetector") then-- This will check if the button that you wanted to be pressed has an click detector, if no, then it will create one.
return
else
CD = Instance.new("ClickDetector", Button)
end
if CD then-- If CD exists, then:
CD.MouseClick:Connect(function()
game.ReplicatedStorage:WaitForChild("PremadeIntro"):FireAllClients()--Fires the remoteEvent for all clients.(Players.)
end)
end