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

If player has 100 Coins then can get pet?

So I want when the player has 100 coins (leaderstat) and if they click this gui button they will get the pet and if they dont have the amount of money it will print "Need more cash" but its not working! and I dont see any errors

local pet = game.Lighting.Pet2:Clone()
local plr = game.Players.LocalPlayer
local cash = script.Parent.Parent.Parent.Parent.leaderstats:WaitForChild("Coins")

script.Parent.MouseButton1Click:Connect(function()
	if cash.Value == 100 then
		pet.Parent = plr.Character
	else
		print("Need more cash!")
	end
end)

1 answer

✓ Accepted answer

Try doing >= which means greater than or equals than == which means absolutely equals, so your script should be:

local pet = game.Lighting.Pet2:Clone()
local plr = game.Players.LocalPlayer
local cash = script:FindFirstAncestorOfClass("Player"):WaitForChild("leaderstats").Coins

script.Parent.MouseButton1Click:Connect(function()
	if cash.Value >= 100 then
		pet.Parent = plr.Character or plr.CharacterAdded:Wait()
	else
		print("Need more cash!")
	end
end)

Hope this works!

1 comment

0

Thanks!

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