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

When I buy the axe with the right amount of cash.. When I buy it without I get it for free?

I made a script about a Gui Tool shop. (I'm making a game inspired / based off of Old School Runescape. I made a shop gui to buy a axe. When you buy the "Cash" From the leaderboard goes down by 10. (I made the leaderboard with 15 "Cash". When you buy it you can spam click it to buy how many axe you want for free! It seems that when you only have "Cash > 10 it will minus ten. But when you don't you get it for free (Sorry for the lack of grammar)

---Sever Script---

local Event = game.ReplicatedStorage.RemoteEvent

Event.OnServerEvent:Connect(function(player, toolName) local clonedTool = game.ReplicatedStorage:FindFirstChild("Axe"):Clone() clonedTool.Parent = player.Backpack end)

local Event = game.ReplicatedStorage.RemoteEvent

Event.OnServerEvent:Connect(function(player, toolName) if player.leaderstats.Cash.Value >= 10 then

    player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 10
    local clonedTool = game.ReplicatedStorage:FindFirstChild():Clone()
    clonedTool.Parent = player.Backpack
    
    player.leaderstats.Cash.Value = player.leaderstats.Cash.Value -10 
          
    
end

end)

Really hope you can help.

---Local Script---

local Event = game.ReplicatedStorage.RemoteEvent local toolName = "Axe"

script.Parent.MouseButton1Click:Connect(function() -- when player clicks the button Event:FireServer(toolName) end)

1 comment

0

please format your entire script

1 answer

✓ Accepted answer

You need to code what happens when the player doesn't have enough or already owns the item. Give the player a BoolValue when they buy the tool. At the beginning, I checked whether or not they had it. If they didn't, that means they haven't bought the tool yet. I fixed up your script as well. Don't have two separate functions for the cash deduction and the cloning of the tool.

local Event = game.ReplicatedStorage.RemoteEvent

Event.OnServerEvent:Connect(function(player, toolName) 
	if player.leaderstats.Cash.Value >= 10 and player:FindFirstChild(toolName) == nil then
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 10
		local clonedTool = game.ReplicatedStorage:FindFirstChild(toolName):Clone()
		clonedTool.Parent = player.Backpack
		local ownsTool = Instance.new("BoolValue")
		ownsTool.Name = toolName
		ownsTool.Parent = player
	elseif player.leaderstats.Cash.Value < 10 then
		print("Not enough cash!")
	else
		if player:FindFirstChild(toolName) then -- checking to see if they have the BoolValue
			print("Player already owns tool!")
		end
	end
end)

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