Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I Make A ClickDetector shop?[Answered by Soban06]

Asked by 4 years ago
Edited 4 years ago

Hello scriptinghelpers users. I Have a question How do i make a click detector shop FOR example You click the gun that costs 20 money And the money gets taken from ur leaderboard money. If the player doesnt have number "20" He doesn't get the gun. Please help! If you don't understand just don't answer.

0
Is the Gui all set up? Soban06 410 — 4y
0
And what about the leaderstats. If they both of these things are set up, then I can help you. Soban06 410 — 4y
0
Gui is not set up but, leaderstat ready Br0kenM1ndss 7 — 4y
0
for click detectors, you can make it the same as how soban showed but you don't need the local script. player is the only parameter in mouseclick so you can use that to get the player, you also get to check the stats from the server script as well which would prevent exploiters from getting items. BulletproofVast 1033 — 3y

1 answer

Log in to vote
2
Answered by
Soban06 410 Moderation Voter
4 years ago

Alright, let's do this. It might be a bit long. But I will explain everything on the way.

First of all, make sure you have a screen gui and inside of that screen gui, a textbutton. We will click this button to get the item. You can customize it the way you want.

Now make sure that your tool you want to give (in this case, it should be the gun) is inside of the replicated storage.

And also create a Remote Event inside the Replicated Storage. Call it "GiveGun"

Inside the text button we created earlier, insert a local script.

local Player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Price = 50 -- Change it to the price you want the item to be.

Here we have just defined some simple variables.

Now, we will check if the player has clicked on the text button. If they do, we will check if they have enough money, and if they do, we will check if they already have the gun in their backpack (so that they don't spam their backpack). If they don't, then we give them the gun and reduce their money.

So here is the rest of the code:

local Player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Price = 50 -- Change it to the price you want the item to be.

script.Parent.MouseButton1Click:Connect(function()

    if Player.leaderstats.Money.Value >= Price then -- Change "Money" to the stat you have in leaderstats.

        if not Player.Backpack:FindFirstChild("Gun") then -- Checking if the player already has the Gun in their backpack. If they don't, then we give them gun.

            game.ReplicatedStorage.GiveGun:FireServer() -- Firing a Remote Event so that the rest of the processing could be handled by the server.

        end

    end
end)

Now next, create a script inside the 'ServerScriptService'. Call it anything you want. This will handle the remote event we fired earlier.

Add this inside of it:

game.ReplicatedStorage.GiveGun.OnServerEvent:Connect(function(player)
        player.leaderstats.Money.Value -= 50 -- Change "50" to the price of the item.
        game.ReplicatedStorage.Gun:Clone().Parent = player.Backpack
        game.ReplicatedStorage.Gun:Clone().Parent = player.StarterGear
end)

This should successfully give the gun to the player.

If you have any queries, let me know.

I will be glad to help.

Ad

Answer this question