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

It's a return value problem I'll explain my problem in my comment could you help ?

Asked by 5 years ago

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 :

01function Oncliked(player)
02local stats = player:findFirstChild("leaderstats")
03local cost = stats:findFirstChild("Money")
04if cost == nil then return false end
05if 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
06if cost.Value >= 75 then
07cost.Value = cost.Value - 75
08end
09 
10 
11print("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.

0
Try other things like if cost.value > 75 then St_vnC 330 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.

01script.Parent.MouseButton1Click: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
View all 23 lines...

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.

0
Bon tout d'abord merci de vouloir m'aider ,ton script fonctionne mais le problème c'est que je n'arrive pas a faire ce que je souhaite . Ce que je veut c'est si je n'ai pas assez d'argent le script va s’arrêter et quand j'aurais gagner de l'agent je pourrai re acheter. PS: je voudrai bien montrer le script complet mais il est un peu grand donc je ne peu pas l'afficher inconue88 3 — 5y
0
en plus simple quand je n'ai plus assez d'argent le message s'affiche mais quand je regagne de l'argent et que j'ai ce qui faut le script rest bloquer sur le message "not enought money" inconue88 3 — 5y
0
Allo! Désolé de ne pas avoir répondu plus tôt, je ne sais pas pourquoi, les notifs marchaients pas. jsp pqoi mais... :/ - Peux-tu me montrer ton script? Mets le sur pastebin ou quelque chose. lolol1901 28 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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

01local 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 itemClone2 = tool:Clone()
14 
15        itemClone.Parent = player.Backpack
View all 24 lines...

And that's all! Please let me know if it works!

0
your script is a little bit same as the lolol1901's script so my problem is the same when I don't have enought money It print "you don't have enought money" but when I get back money the script is still printing "you don't have enought money" inconue88 3 — 5y

Answer this question