Code is broken but nothing is showing in the output?

I have a code that is similar to the one in Anime Fighting Simulator. It is activated when the Player clicked the character. PlayerStats is a folder inside of the Player.

When the player activates the function it is designed for the player’s HumanoidRootPart to be anchored and the output to print, Clicked. The problem is nothing would happen, the output isn’t showing any errors and it won’t print out Clicked. I don’t know what is causing this because this was working until I added some more code with a completely diffrent function inside this script.

This is a local script.

local Player = game.Players.LocalPlayer

workspace.Mechanism.Kakashi.ClickDetector.ClickDetector.MouseClick:Connect(function()
	if Player:WaitForChild("PlayerStats").KakashiCurrentQuest == 0 then
		print("Clicked")
		Char.HumanoidRootPart.Anchored = true
		GameFrame.BottomBar.Visible = false
		GameFrame.QuestFrame.Visible = true
		GameFrame.QuestFrame.Details.ImageLabel.Image = "rbxassetid://6490618849"
		GameFrame.QuestFrame.Details.NameChar.Text = "Cakashi"
		if Player:WaitForChild("PlayerStats").KakashiQuest.Value == 1 then
			GameFrame.QuestFrame.Details.Reward.Text = "Reward: "..Kakashi1
			GameFrame.QuestFrame.Details.DesText.Text = "I have losted my kunai, I think I losted it some where near the Hokage's office. Can you help me find it?"
	else
		GameFrame.ExtraText.Visible = true
		GameFrame.ExtraText.Text = "It seems like you already have a quest, if this is a bug contact @MePlayzGames on Twitter."
		wait(5)
		GameFrame.ExtraText.Visible = false
	   end
	end
end)

What is the Player variable supposed to be? Also what kind of script is it? Local or Server?

When the MouseClick event of a ClickDetector is activated and connected to a function, you’re able to reference the player that activated it. However, you didn’t add a parameter for this function that would allow you to reference that player.

If this is in a LocalScript, you can simply define the LocalPlayer through the Players service but for server scripts, the following would need to be done:

... ClickDetector.MouseClick:Connect(function(player) -- Parameter of "player" that will reference the player that activated the ClickDetector

    print(player.Name.." activated the ClickDetector")

    local PlayerStats = player:FindFirstChild("PlayerStats")

    if PlayerStats then
        -- Continue with the rest of the codeblock
    end
end

Is local, player is just the local player.

This was in a local script, I didn’t add the Player part because it would make the script too long. In the preview.

Ah I see – and I just realized what is probably causing it to work improperly:

If the “KakashiCurrentQuest” is a ValueObject, you need to refer to its Value property before checking what it’s equal to, otherwise, you’re checking if the Instance is equal to 0.

1 Like

You should implement the Clicked print outside the if statement, and add another one inside to make sure that it does work (And 1 more in the else statement if for some reason it doesn’t meet the correct requirements)

1 Like

That is what I’m trying to do, if the player’s value inside of that stringvalue == 0 then they can continue.

...KakashiCurrentQuest.Value == 0 then
is what it should be

2 Likes