Refusing to match UserId

I’ve been trying to figure out why this userid hasn’t been working at all lately, and I hav not yet found a solution nor anything would answer this for me.

I’m confused on how this would be rejected as it’s a normal function, is there something wrong with Roblox or what?

Code:


local Settings = script.Parent:WaitForChild("Settings")
local PlayerAvailable = Settings:WaitForChild("AvailablePlayer")

Detector.Touched:Connect(function(Hit)
	if Hit.Parent:FindFirstChildWhichIsA("Humanoid") then
		local Humanoid = Hit.Parent:FindFirstChildWhichIsA("Humanoid")
		if Humanoid.Health > 0 then
			if game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent) then
				local Player = game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent)
				local UserId = Player.UserId
				if PlayerAvailable.Value == UserId then
					return warn("TRUE")
				else
					print(Hit.Parent.Name)
					return warn("FALSE")
				end
			end
		end
	end
end)

I’d appreciate the help.

Hey, just to confirm PlayerAvailable.Value is an integer, right?

By refusing to match I assume you mean that the if statement won’t run, right?

Yep pretty much, I’ve tried solving it through many ways but never appeared to work.

Would you be able to send me a screenshot of the properties tab for Settings.AvailablePlayer? Just want to double check here!!

1 Like

image

local Settings = script.Parent:WaitForChild("Settings")
local PlayerAvailable = Settings:WaitForChild("AvailablePlayer")
local Detector = script.Parent

Detector.Touched:Connect(function(Hit)
	if Hit.Parent:FindFirstChildWhichIsA("Humanoid") then
		local Humanoid = Hit.Parent:FindFirstChildWhichIsA("Humanoid")
		if Humanoid.Health > 0 then
			if game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent) then
				local Player = game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent)
				local UserId = Player.UserId
				PlayerAvailable.Value = UserId
				if PlayerAvailable.Value == UserId then
					return warn("TRUE")
				else
					print(Hit.Parent.Name)
					return warn("FALSE")
				end
			end
		end
	end
end)

image

1 Like

PlayerAvailable.Value = UserId

Since you never set that value to anything, it was just 0. And thus, it wouldn’t warn ‘TRUE’.

If I understand you right.

1 Like

Realising my mistake, the reason why it must’ve been non-functioning is because I placed a number to a string value which caused it to break the statement as you cant compare strings to nums unless doing tonumber(StringValue) == num

Apologies as this must’ve been a waste of time, I will delete this post but sincerely please forgive me as I thought I made it a number value not a string value.

I should probably start checking properties and etc before assuming the code is broken.

No, do not delete it, I believe it might help some beginners.

No problems :slight_smile:

1 Like

Ah that might be helpful towards others so therefore I guess you’re completely right, I hope this helps out beginners that are new to coding.

No worries. I mean, if you really wanted to continue this on a StringValue you could with

	if tonumber(PlayerAvailable.Value) == UserId then

But honestly there is no purpose in that considering that you have the issue solved now and there is really no advantage to having this as a stringValue rather than IntValue

Glad you found the issue. :slight_smile:

Thank you guys for helping me out and realizing my mistake of the type value that I incorrectly placed.

Appreciate the support ^