Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does it not allow me to change the userstats?

I'm making a house purchase brick so when you touch it, it'll remove the stats/money and make you owner of the house.

But it says on line 25 "attempt to compare userdata with number" and I do not understand what it means, Could someone help?

Here's the script:

local ting = 0 
owner = script.Parent.Parent.Parent.OwnerName 

function onTouched(hit)

	if ting == 0 then 
	ting = 1 
	check = hit.Parent:FindFirstChild("Humanoid") 

	if check ~= nil then
		
		local user = game.Players:GetPlayerFromCharacter(hit.Parent)
		if (user:FindFirstChild("rig") ~= nil) then 

		local user = game.Players:GetPlayerFromCharacter(hit.Parent) 
		local message = Instance.new("Message")
		message.Text = "You already own a house"
		message.Parent = user
		wait(3)
		message:remove()

		else
			
 local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr.leaderstats.Money <= 1500 then
	
	local money = game.Players:GetPlayerFromCharacter(hit.Parent).leaderstats.Money
		money.Value = money.Value -1500
	
		local user = game.Players:GetPlayerFromCharacter(hit.Parent)
		owner.Value = hit.Parent.Name 
		
		local own = Instance.new("IntValue")
		own.Name = "rig"
		own.Parent = user


		local message = Instance.new("Message") 
		message.Text = "House Purchased"
		message.Parent = user 
		wait(3) 
		message:remove() 
		

		script.Parent.Parent:remove()

end
		end
	
end
end
	ting = 0 
	end

script.Parent.Touched:connect(onTouched)

3 answers

This is a simple fix. Money is an actual value instance. This includes IntValues, NumValues, and Color3Values, as well as a few more. To fix the error, you simply need to index the Value property of the object.

local ting = 0 
owner = script.Parent.Parent.Parent.OwnerName 

function onTouched(hit)

    if ting == 0 then 
    ting = 1 
    check = hit.Parent:FindFirstChild("Humanoid") 

    if check ~= nil then

        local user = game.Players:GetPlayerFromCharacter(hit.Parent)
        if (user:FindFirstChild("rig") ~= nil) then 

        local user = game.Players:GetPlayerFromCharacter(hit.Parent) 
        local message = Instance.new("Message")
        message.Text = "You already own a house"
        message.Parent = user
        wait(3)
        message:remove()

        else

 local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr.leaderstats.Money.Value <= 1500 then

    local money = game.Players:GetPlayerFromCharacter(hit.Parent).leaderstats.Money
        money.Value = money.Value -1500

        local user = game.Players:GetPlayerFromCharacter(hit.Parent)
        owner.Value = hit.Parent.Name 

        local own = Instance.new("IntValue")
        own.Name = "rig"
        own.Parent = user


        local message = Instance.new("Message") 
        message.Text = "House Purchased"
        message.Parent = user 
        wait(3) 
        message:remove() 


        script.Parent.Parent:Destroy() --remove is deprecated

end
        end

end
end
    ting = 0 
    end

script.Parent.Touched:Connect(onTouched) --connect deprecated

The reason why is because you're comparing the Money object to a number, but what you need to do is get the value of the Money object and compare it to a number:

Btw, I don't think it's your intention to check if the player's money is less than or equal to 1500. I think you meant to check if it's greater or equal to 1500.

<= - less than or equal to >= - greater than or equal to

if plr.leaderstats.Money.Value >= 1500 then

end

2 comments

0

i like how 3 answers came up within 1 minute of each other

0

yes but mine is the best

nice man

now u realize that u need to do

plr.leaderstats.Money.Value -- emphasis on last word

right?

This discussion is preserved as it was. New answers, comments, and votes are closed.