Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Start of CreateButton
- function CreateDict(Table)
- local PlayerF = {}
- for i,v in next, Table do
- if not v:IsA("Folder") then
- PlayerF[v.Name] = v.Value
- end
- end
- return PlayerF
- end
- function Count(Table)
- local Count = 0;
- for i,v in next, Table do
- Count = Count+1
- end
- return Count;
- end
- function Check(PFolder,Requirments)
- local Count = 0;
- for i,v in next, Requirments do
- if tonumber(PFolder[i]) ~= nil and PFolder[i] and tonumber(PFolder[i]) >= tonumber(v) then
- Count = Count+1;
- elseif tostring(PFolder[i])~= nil and PFolder[i] and tostring(PFolder[i]) == tostring(v) then
- Count = Count+1;
- end
- end
- return Count;
- end
- --[[Button must be the button instance not the click detector,
- Requirements must be the dictionary of Requirements
- Stat is the Stat to be indexed if they meet the requirement
- Value is what the stats value should be set to if they meet the requirement
- --]]
- function CreateClick(Button,Requirements,Stat,Value)
- local Original = Button.Name;
- local Debounce = false;
- Button.Head.ClickDetector.MouseClick:connect(function(PLAYER)
- if Debounce then
- return
- end
- local PFolder = game:GetService("ServerStorage").PlayerFolders:WaitForChild(tostring(PLAYER))
- local PFolderDict = CreateDict(PFolder:GetChildren());
- if Count(Requirements) ~= Check(PFolderDict,Requirements) then
- Button.Name = "Improper requirements";
- Debounce = true;
- wait(2);
- Debounce = false;
- Button.Name = Original;
- elseif Count(Requirements) == Check(PFolderDict,Requirements) then
- Debounce = true;
- if Requirements["Gold"] then
- PFolder.Gold.Value = PFolder.Gold.Value - Requirements["Gold"];
- end
- if Requirements["Bounty"] then
- PFolder.Bounty.Value = PFolder.Bounty.Value - (Requirements["Bounty"]/2);
- end
- PFolder[Stat].Value = Value;
- Button.Name = "Success!"
- wait(2);
- Debounce = false;
- Button.Name = Original;
- end
- end)
- end
- --End of CreateClick function
- --This is an example of how it should look like
- local CyborgReq3 = {["LVL"] = 15, ["Gold"] = 40000,["Race"] = "Cyborg",["CyborgUpgrade2"] = true,["CyborgUpgrade3"] = false}
- CreateClick(workspace["Cyborg Upgrade3 [40k Beli] [Level 15]"],CyborgReq3,"CyborgUpgrade3",true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement