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

Confusing error, help please? [SOLVED]

I'm getting too many complaints on this not working. But I don't know how to fix it, please help?

I have the following code for a currency converter. I use DataStore to save statistics. Could that be why it doesn't work?

button = script.Parent
WhatIHave = script.Parent.Parent.WhatIHave
Estimated = script.Parent.Parent.Estimated.Value
p = game.Players.LocalPlayer
button.MouseButton1Click:connect(function ()
	if p.leaderstats.Cash >= WhatIHave.Value then
		p.leaderstats.Cash = p.leaderstats.Gems - WhatIHave.Value
		p.leaderstats.Diamonds = p.leaderstats.Diamonds + Estimated.Value
		repeat
			i = 1 
			script.Parent.Text = "Transaction Complete"
			wait(0.5)
			script.Parent.Text = ""
			i = i+1
		until i==5
	else
		repeat
			i = 1 
			script.Parent.Text = "Insufficient Funds"
			wait(0.5)
			script.Parent.Text = ""
			i = i+1
		until i==5
	end
end)

The output says attempt to compare number with userdata Line 6. Similar issue when someone buys a developer product. It won't give what they bought.

buybutton = script.Parent
msp = game:GetService("MarketplaceService")
id = 19251902
p = game.Players.LocalPlayer
buybutton.MouseButton1Click:connect(function ()
	msp:PromptPruouctPurchase(p,id)
	p.leaderstats.Diamonds = p.leaderstats.Diamonds + 10
end)

Output: attempt to perform arithmetic on field 'Diamonds' (a userdata value) Line 7

I need to fix this as soon as possible, as this is causing mayhem on my game.

Everything is in a LocalScript

2 answers

✓ Accepted answer
button = script.Parent
WhatIHave = script.Parent.Parent.WhatIHave
Estimated = script.Parent.Parent.Estimated.Value
p = game.Players.LocalPlayer
button.MouseButton1Click:connect(function ()
    if p.leaderstats.Cash.Value >= WhatIHave.Value then
        p.leaderstats.Cash.Value = p.leaderstats.Gems.Value - WhatIHave.Value
        p.leaderstats.Diamonds.Value = p.leaderstats.Diamonds.Value + Estimated.Value
        repeat
            i = 1 
            script.Parent.Text = "Transaction Complete"
            wait(0.5)
            script.Parent.Text = ""
            i = i+1
        until i==5
    else
        repeat
            i = 1 
            script.Parent.Text = "Insufficient Funds"
            wait(0.5)
            script.Parent.Text = ""
            i = i+1
        until i==5
    end
end)
buybutton = script.Parent
msp = game:GetService("MarketplaceService")
id = 19251902
p = game.Players.LocalPlayer
buybutton.MouseButton1Click:connect(function()
    msp:PromptProductPurchase(p, id)
    p.leaderstats.Diamonds.Value = p.leaderstats.Diamonds.Value + 10
end)

1 comment

0

Got it. Thanks!

Hmmm im not to sure i will give it a secound and ill see

1 comment

0

Please do. I really need this help :D

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