MouseClick:connect(player) - player argument is not being defined

Script:

script.Parent.MouseClick:Connect(function(player)
	if player then
		player.Statistics.Thirst.Value = 100
	end
end)

Why isn’t my Thirst value not changing to 100?

Thanks so much!

3 Likes

add a print(player) before the if
make sure it’s firing and that the player is correct
double check the player>statistics>thirst hierarchy

It doesn’t print anything. I’m not sure…

the instance.MouseClick
instance needs to be your clickdetector

it is. The script is inside of the click detector

this works for me with part>clickDetector>script

script.Parent.MouseClick:Connect(function(player)
	if player then
		print(player)
	end
end)

you can’t get it to print at all?

is it a local script or a regular script?

it didn’t work when i changed it to local

Try checking the properties of the ClickDetector and Script and make sure its in a clickable range and nothing is disabled

Also it’s possible that player.Statistics.Thirst.Value = 100 is not a valid property path

local statistics = player:FindFirstChild("Statistics")
if statistics then
    local thirst = statistics:FindFirstChild("Thirst")
    if thirst then
            ... your code here ...
    else
        print("Houston we have a problem finding thirst")
    end
else
    print("Houston we have a problem finding statistics")
end

This sounds like an issue with the properties of the ClickDetector and the Script itself. Make sure you’re using a Script and not a LocalScript or ModuleScript.

script.Parent.MouseClick:Connect(function(player)
	if player then
		print(player)
	end
end)

This repro by Pharyx_Styx works as intended. If this is not producing any result in the output, it is most likely a user error. Make sure you’re using a Script and not a LocalScript!

Also it is possible that the value is properly changing (on the server) you might just be seeing the local values of the player. Try clicking this in studio

studio

and when it says “Current: Server” look at the player directory

2 Likes

I’m using a script, and it still won’t work. :thinking:

Didn’t work. This stayed at 60 (a random number I just put it at through properties.)

Didn’t work for me. :thinking:

Open a new place and create a basic repro of your Part with the ClickDetector, and insert the same code snippet that Pharyx_Styx wrote earlier. It worked for me when I did so.

How sure are you that the Script itself is not Disabled? If you’re working in a Team Create place, try clicking Apply Changes/Edit at the very top inside the toolbar.

1 Like

This worked. Just doesn’t work in my real game.

What do you mean? What child would I wait for?

Nothing happens. Here’s my script I just re-wrote:

script.Parent.ClickDetector.MouseClick:Connect(function(player)
	if player then
		print(player)
		if player:WaitForChild("Statistics"):WaitForChild("Thirst") then
			player.Statistics.Thirst.Value = 100
			print("success")
		end
	else
		print("nope")
	end
end)

Does it mean anything that the instance cannot be seen by other players? (It’s cloned by the client, not the server.)

1 Like

For something to be viewed on the server, it must be on the server in the first place You should put the statistics into the player from the server.