So the things is I pay a box to get a gun , the box cost actually 75 bucks (in game), the box work but when our currency is less than 75, the box still work and the thing that I want to do is when our currency is less than 75 then we cannot buy box until we get more than 75 .
My script is here :
01 | function Oncliked(player) |
02 | local stats = player:findFirstChild( "leaderstats" ) |
03 | local cost = stats:findFirstChild( "Money" ) |
04 | if cost = = nil then return false end |
05 | if cost.Value < 75 then return end --- It's the thing that I tried to break the script if we didn't have less than 75 buck |
06 | if cost.Value > = 75 then |
07 | cost.Value = cost.Value - 75 |
08 | end |
09 |
10 |
11 | print ( "Enough Money" ) |
ps: I cut only the currency part because I cannot post the entire script and the script is a bit in french because I speak french.
Salut! Je parle français aussi, donc je rédigerais cette réponse en français.
En premier, organise ton code. On veut un code organisé, c'est mieux qu'un qui marche très bien. En fait, c'est juste mon avis.
En deuxième, fais attention à FindFirstChild(), tu écris findFirstChild(). Je sais pas vraiment s'il y a un changement, mais c'est juste meilleur d'utiliser FindFirstChild(). C'est une bonne pratique.
Finalement, voici le code que tu cherche pour remplacer le tien. Organisé, en plus. Assure toi que c'est un LOCALSCRIPT.
01 | script.Parent.MouseButton 1 Click:Connect( function () -- Psst, je sais pas si tu as quelque chose qui définit OnClicked à MouseButton1Click, donc j'ai juste utilisé la function MouseButton1Click. En plus, est-ce que ce Script est dans le bouton? Si non, assure toi de réparer la fonction. |
02 |
03 | local player = game.Players.LocalPlayer |
04 | local stats = player:WaitForChild( "leaderstats" ) |
05 | local money = stats:FindFirstChild( "Money" ) |
06 |
07 | if money < = 74 then |
08 |
09 | print ( "Not enough money!" ) |
10 |
11 | else |
12 |
13 | print ( "Vous avez assez d'argent! Vous pouvez acheter cet article." ) |
14 | money = money - 75 |
15 | -- En plus, ici, si vous vendez un Tool, vous pouvez faire quelque chose du genre |
J'espère que je t'ai aidé, dis moi si tu trouve un problème. Le mieux ici, ce que le code est organisé! Bof, il pourrait être plus organisé mais j'ai laissé des commentaires pour que tu comprennes mieux le code.
P.S. J'ai compris que tu parlais en français tout d'abord avec ton pseudo... P.P.S. Réponds moi une fois que tu regarde cette réponse.
Well... Isn't complicated.
All you need to do is verify if the player have or not the enough money and then give the player the item if they have enough or give them a warning if they don't have the enough money
Lets go to the code
Put it all on a LocalScript and the LocalScript create it on the Button
01 | local function mouseClick(click) |
02 | local player = game.Players.LocalPlayer |
03 | local leaderstats = player:WaitForChild( "leaderstats" ) |
04 | local currency = leaderstats.Money --> Change it to you currency name |
05 | local RS = game:GetService( "ReplicatedStorage" ) -->We have the tool on the RS |
06 | local tool = RS:WaitForChild( "Tool" ) --> Change it to your tool name |
07 |
08 | if currency.Value < = 75 then |
09 | print ( "You don't have enough money!" ) |
10 | elseif currency.Value > = 75 then |
11 | currency.Value = currency.Value - 75 --> Change it to your price |
12 | local itemClone = tool:Clone() |
13 | local itemClone 2 = tool:Clone() |
14 |
15 | itemClone.Parent = player.Backpack |
And that's all! Please let me know if it works!