How to fix this dialouge bug in my game?

I’m currently making a talking system with the value “IsTalking” (boolvalue) within the player’s character. It works for the first half, but attempting exiting the dialogue results in the dialogue box closing, but the player being stuck in place.
Here’s the error:


Script:

script.Parent.MouseButton1Down:Connect(function(plr)
   local istalking = plr.Character:WaitForChild("IsTalking")
   istalking.Value = false
   game.Workspace.Race:Play()
   local flag = game.ServerStorage.Flag:Clone()
   flag.Parent = workspace
   game.Workspace.Test.ClickPart:Destroy()
end)

I’m not sure of what the script’s parent is, but it look like MouseButton1Down takes a parameter that is a number, not a player. If this is in a local script, you can just get the player’s character by writing: game.Players.LocalPlayer.Character

GuiButton | Roblox Creator Documentation has no player as a parameter and this must be in a local script, not a server script. Use an RemoteEvent | Roblox Creator Documentation to replicate to the server.

I tried this, but it didn’t seem to work. I’m not the most familiar with how RemoteEvents work, but I somewhat understand how to use them. I put this into a LocalScript:

script.Parent.MouseButton1Down:Connect(function(plr)
	plr.Character.IsTalking.Value = false
	local exit = game.ReplicatedStorage:WaitForChild("ChallengeDialogueExited")
	exit:FireServer()
end)

And this into a Script inside the RemoteEvent, which in turn is inside ReplicatedStorage:

script.Parent.OnServerEvent:Connect(function()
	game.Workspace.Race:Play()
	local flag = game.ServerStorage.Flag:Clone()
	flag.Parent = workspace
	game.Workspace.Test.ClickPart:Destroy()
end)

The flag is for a race mission, touching it will end the race. The Race sound is the music for the race.

Try putting the script in ServerScriptService.

Didn’t seem to change the outcome. I also get the same "attempt to index number with “Character” error.

Use Players | Roblox Creator Documentation in a local script. Also, like I said, the MouseButton1Down event doesn’t have a player as a parameter.

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Down:Connect(function()
	player.Character.IsTalking.Value = false
	local exit = game.ReplicatedStorage:WaitForChild("ChallengeDialogueExited")
	exit:FireServer()
end)

Thank you! With a bit of tinkering I managed to fix the issue, now I have to apply to the rest of the dialogue system which shouldn’t be too hard.