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

Error: attempt to compare userdata with number?

So I am currently trying to make a shop for my group's game, Bloxxer. I have created 2 scripts for the game. One is a ServerInvoke script and the other is a purchase script. I keep getting this error: attempt to compare userdata with number Could anyone help? ServerInvoke:

game.ReplicatedStorage.PurchaseItem.OnServerInvoke = function(CertainPlayer, Item, Parent, Price)
	if CertainPlayer:WaitForChild("leaderstats").Coins.Value >= Price then
		CertainPlayer.leaderstats.Coins.Value = CertainPlayer.leaderstats.Coins.Value - Price
		local Tool = Parent[Item]:Clone()
		Tool.Parent = CertainPlayer.Backpack

        local Tool = Parent[Item]:Clone()
		Tool.Parent = CertainPlayer.StarterGear
		return true
	else
		return false
	end
end

Purchase:

local AlreadyPurchased = false
script.Parent.Text = "Buy for 15 Coins"

script.Parent.MouseButton1Click:Connect(function()
	if AlreadyPurchased == false then
		local CertainPlayer = game.Players.LocalPlayer
		local Item = game.ReplicatedStorage.Shop.Items.FakeKnife.Tool.Name
		local Parent = game.ReplicatedStorage.Shop.Items.FakeKnife
		local Price = 15
		local Purchased = game.ReplicatedStorage.PurchaseItem:InvokeServer(CertainPlayer, Item, Parent, Price)
		
		if Purchased == true then
			AlreadyPurchased = true
			script.Parent.Text = "Purchased!"
			wait(2.5)
			script.Parent.Text = "Buy for 15 Coins"
		else
			script.Parent.Text = "Failed to purchase!"
			wait(2.5)
			script.Parent.Text = "Buy for 15 Coins"
		end
	elseif AlreadyPurchased == true then
		script.Parent.Text = "Already purchased!"
		wait(2.5)
		script.Parent.Text = "Buy for 15 Coins"
	end
end)

1 answer

✓ Accepted answer

I remember having this problem but I'll give you an example of why it's happening serverscript

event.OnServerEvent(player, something1, something2)--no matter what you send player is always the first parameter

localscript

event:FireServer(something1, something2)--i didn't send the player but it got the player

meaning all you would need to do is change this line

  local Purchased = game.ReplicatedStorage.PurchaseItem:InvokeServer(Item, Parent, Price) --don't send the player

btw this is line 10 of your localscript

2 comments

0

Confused, what am I meant to do.

0

^ Didn't read all of it, but it worked! Thank you for the help!

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