I tried making a whole new approach to the GUI script. It will not work

Hello everybody!!! I’m back! But now with a new problem with scripting. I feel I may be nagging a bit, but I really need help with this. So, I tried a whole new approach to the script and decided to make it switch between the NPC talking and a random player talking. Again, I DID try following the tutorial for this script, (this script is by rubyboo4) but will not work. If I could get some help, that would be awesome!

local CreateDialogueEvent = game.ReplicatedStorage.CreateDialogueEvent

local randomPlayerName
local randomPlayerID

local function getRandomPlayer()
	local players = game.Players.getPlayers()
	local number = math.random(1,#players)
	local randomPlayer = players[number]
	randomPlayerName = randomPlayer.Name
	randomPlayerID = randomPlayer.UserID
end

local function challeng_example()
	local noob_image = "rbxassetid://4999968209"
	CreateDialogueEvent:FireAllClients(noob_image,"Dialogue Here")
	wait(5)
	getRandomPlayer()
	CreateDialogueEvent:FireAllClients(getPlayerImage(randomPlayerID),"Dialogue Here")
end

local function challenge_intro
	wait(10)
	getRandomPlayer()
	CreateDialogueEvent:FireAllClients(getPlayerImage(randomPlayerID),"You can say that again. I can't wait to play at the park!")
	wait(4)
	local noob_image = "rbxassetid://4999968209"
	CreateDialogueEvent:FireAllClients(noob_image, "So what are we waiting for? Let's go!!!")
	wait(5)
	game:GetService("StarterGui"):FindFirstChild("TalkingNPC").Frame.Visible = false
end

local function challenge_1()
	
end

local function challenge_2()

end
	
local function challenge_3()
	
end

local function challenge_4()
	
end

local function challenge_ending()

end

local function startGame()
	challenge_intro()
	challenge_1()
	challenge_2()
	challenge_3()
	challenge_4()
	challenge_ending()
end

wait(10)
startGame()

This is my code. There are multiple events here that you shouldn’t worry about. Please let me know if you can fix it! (Lua really isn’t my strongest coding language. :sweat_smile:)

Edit: When I go into a test, nothing happens in the output table. Literally nothing. What doesn’t seem to be working is probably that I forgot to add a OnClientEvent, but I’m not sure.

Posting any errors that occur in the console would be helpful, along with what doesn’t work right.

It appears that in the code segment above, you are trying to call an undefined function and the function challenge_intro is missing parentheses. Lua isn’t my strongest language, but I know for a fact that will cause an error.

I don’t think that you are able to do this anymore.
I think it’s supposed to be game.Players:GetPlayers()

Also I hope u made the OnClientEvent in local script that will listen for those FireAllClients

Oh! I forgot to add that in! My apologies!

I still cannot find a working solution for this. If you have one, let me know! :smiley: