Why are these scripts not working. I am trying to get it to where the player presses a TextButton, it fires a remote event that changes the text of a surfacegui textlabel under a part to a random joke. It changes for all players. It’s not working.
I have no idea where to start.
Script 1 - StarterGui
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("ChangeJokeText")
local textButton = script.Parent
local function onButtonClicked()
remoteEvent:FireServer()
end
textButton.MouseButton1Click:Connect(onButtonClicked)
Script 2- - ServerScriptService
-- ServerScriptService
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local remoteEvent = ServerScriptService:WaitForChild("ChangeJokeText")
local jokes = {
"Why don't some couples go to the gym? Because some relationships don't work out!",
"I told my wife she was drawing her eyebrows too high. She seemed surprised.",
-- Add more jokes here
}
remoteEvent.OnServerEvent:Connect(function(player)
local randomJoke = jokes[math.random(1, #jokes)]
local jokeTextLabel = game.Workspace:FindFirstChild("JokeTextLabel")
if jokeTextLabel and jokeTextLabel:IsA("TextLabel") then
jokeTextLabel.Text = randomJoke
end
end)