> Hello i am having this problem where the shop gives a random tool to the player without it being bought does anyone know as to why? here are the two scripts
>
> >wait(.1);
> -- Start
> System={};
> -- Currency
> System.CurrencyName="Coins"; ITEMS)
> System.Currency=nil;
> -- Services
> System.Services={
> Players=game:GetService("Players");
> Workspace=game:GetService("Workspace");
> Tween=game:GetService("TweenService");
> ReplicatedStorage=game:GetService("ReplicatedStorage");
> StarterGui=game:GetService("StarterGui");
> };
> -- Player
> System.User=System.Services.Players.LocalPlayer;
> System.Character=System.User.Character or System.User.CharacterAdded:Wait();
> -- Assets
> System.TweenInfo=TweenInfo.new(.5,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut);
> System.Items=System.Services.ReplicatedStorage:WaitForChild("ToolsShop"):WaitForChild("Tools"):Clone():GetChildren();
> System.FireEvent=System.Services.ReplicatedStorage:WaitForChild("ToolsShop"):WaitForChild("BuyTool");
> System.UI=script:WaitForChild("UI");
> System.Stand=System.Services.ReplicatedStorage:WaitForChild("ToolsShop"):WaitForChild("Stand");
> -- Tools index
> System.ToolsIndex=System.User:WaitForChild("ToolsIndex")
> -- Sounds
> System.Sounds={
> Buy=System.Services.ReplicatedStorage:WaitForChild("ToolsShop"):WaitForChild("Sounds"):WaitForChild("BuySound");
> Equip=System.Services.ReplicatedStorage:WaitForChild("ToolsShop"):WaitForChild("Sounds"):WaitForChild("EquipSound");
> Unequip=System.Services.ReplicatedStorage:WaitForChild("ToolsShop"):WaitForChild("Sounds"):WaitForChild("UnequipSound");
> Open=System.Services.ReplicatedStorage:WaitForChild("ToolsShop"):WaitForChild("Sounds"):WaitForChild("OpenSound");
> };
> -- Target
> System.TargetPart=System.Services.Workspace:WaitForChild("ToolsShop"):WaitForChild("Touch");
> -- On shop
> System.OnShop=false;
> -- Sort
> table.sort(System.Items,function(Item,Sorted)
> return Item:WaitForChild("Cost").Value<Sorted:WaitForChild("Cost").Value;
> end);
> wait();
> -- // Get item
> function GetItem(Item: Instance)
> -- // Attribute
> Item:SetAttribute("Equiped",true);
> -- // Sound
> System.Sounds.Equip:Play();
> -- // Give
> local Clone=Item:Clone();
> local Weld=Instance.new("Weld",Clone:WaitForChild("Handle"));
> Clone.Parent=System.User.Backpack;
> -- // Weld
> Weld.Name="Weldik";
> if Clone:IsA("Tool") then
> Clone.Equipped:Connect(function()
> Weld.Part0=Weld.Parent
> Weld.Part1=typeof(System.Character:FindFirstChild("RightHand"))=="nil" and System.Character:FindFirstChild("Rigth Arm") or System.Character:FindFirstChild("RightHand");
> end);
> Clone.Unequipped:Connect(function()
> Weld.Part1=nil;
> end);
> end;
> end;
> -- // Remove item
> function RemoveItem(Item)
> if typeof(Item)=="Instance" then
> pcall(function()
> -- // Sound
> System.Sounds.Unequip:Play();
> -- // Item
> Item:SetAttribute("Equiped",false);
> (typeof(System.Character:FindFirstChild(Item.Name))=="nil" and System.User.Backpack:FindFirstChild(Item.Name) or System.Character:FindFirstChild(Item.Name)):Remove()
> end);
> end;
> end;
> -- // Load items
> local LoadItems=function()
> for Index,Item in pairs(System.Items) do
> if typeof(Item)=="Instance" then
> Item:SetAttribute("Owned",(Index<System.ToolsIndex.Value or Index==System.ToolsIndex.Value) and true or false);
> Item:SetAttribute("Equiped",false);
> end;
> end;
> end;
> coroutine.wrap(LoadItems)();
> -- // On index changed
> System.ToolsIndex:GetPropertyChangedSignal("Value"):Connect(function()
> for Index,Item in pairs(System.Items) do
> if typeof(Item)=="Instance" then
> Item:SetAttribute("Owned",(Index<System.ToolsIndex.Value or Index==System.ToolsIndex.Value) and true or false);
> end;
> end;
> end);
> -- // Autoequip
> for Index,Item in pairs(System.Items) do
> if typeof(Item)=="Instance" then
> if Index==System.ToolsIndex.Value then
> -- // Give
> coroutine.wrap(GetItem)(Item);
> end;
> end;
> end;
> -- // Found currency
> for _,Object in pairs(System.User:GetDescendants()) do
> if typeof(Object)=="Instance" then
> if Object:IsA("ValueBase") then
> if Object.Name:lower()==System.CurrencyName:lower() then
> System.Currency=Object;
> end;
> end;
> end;
> end;
> wait();
> -- // Check currency
> assert(typeof(System.Currency)=="Instance","Currency was not found");
> -- // On touched
> System.Character:WaitForChild("Humanoid").Touched:Connect(function(Part)
> if Part==System.TargetPart then
> -- // Check status
> if System.OnShop==true then
> return
> end;
> -- // Original camera state
> local OriginalCameraState=System.Services.Workspace.CurrentCamera.CFrame;
> -- // Unequip tools
> System.Character:WaitForChild("Humanoid"):UnequipTools();
> -- // Give status
> System.OnShop=true;
> -- // Sound
> System.Sounds.Open:Play();
> -- // UI status
> local NewUI=System.UI:Clone();
> NewUI.Parent=System.User.PlayerGui;
> -- // Off core
> System.Services.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All,false);
> -- // Block character
> System.Character:WaitForChild("HumanoidRootPart",3).Anchored=true;
> -- // Load stands locals
> local Stands={};
> local StandNow=1;
> -- // Load stands
> for Index,Item in pairs(System.Items) do
> if typeof(Item)=="Instance" then
> -- // Get stand
> local NewStand=System.Stand:Clone();
> -- // Get item
> local NewItem=Item:Clone();
> -- // Give position
> NewStand:FindFirstChild("Stand").CFrame=NewStand:FindFirstChild("Stand").CFrame+Vector3.new(Index*5,0,0);
> NewStand:FindFirstChild("CameraPart").CFrame=NewStand:FindFirstChild("CameraPart").CFrame+Vector3.new(Index*5,0,0);
> -- // Stand parent
> NewStand.Parent=System.Services.Workspace:WaitForChild("ToolsShop"):WaitForChild("Stands");
> -- // Added stand to table
> table.insert(Stands,NewStand);
> -- // Set item position
> NewItem:FindFirstChild("Handle").CFrame=NewStand:FindFirstChild("Stand").CFrame+Vector3.new(0,3,0);
> NewItem:FindFirstChild("Handle").CanCollide=false;
> -- // Item parent
> NewItem.Parent=NewStand;
> -- // BodyAngularVelocity
> local BodyAngularVelocity=Instance.new("BodyAngularVelocity",NewItem:FindFirstChild("Handle"))
> BodyAngularVelocity.AngularVelocity=Vector3.new(0,1,0);
> -- // BodyPosition
> local BodyPosition=Instance.new("BodyPosition",NewItem:FindFirstChild("Handle"))
> BodyPosition.Position=NewItem:FindFirstChild("Handle").Position
> end;
> end;
> -- // Get camera
> System.Services.Workspace.CurrentCamera.CameraType=Enum.CameraType.Scriptable;
> local UpdateCamera=function()
> pcall(function()
> System.Services.Tween:Create(System.Services.Workspace.CurrentCamera,System.TweenInfo,{CFrame=Stands[StandNow]:FindFirstChild("CameraPart").CFrame}):Play();
> end);
> end;
> coroutine.wrap(UpdateCamera)();
> -- // Get cost
> local UpdateText=function()
> NewUI:WaitForChild("Control"):WaitForChild("Name").Text=tostring(System.Items[StandNow].Name);
> NewUI:WaitForChild("Control"):WaitForChild("Cost").Text="$ "..tostring(System.Items[StandNow]:GetAttribute("Owned")==true and "Owned" or System.Items[StandNow]:WaitForChild("Cost").Value==0 and "Free" or System.Items[StandNow]:WaitForChild("Cost").Value);
> end;
> coroutine.wrap(UpdateText)();
> -- // Get button
> local GetButton=function()
> if System.Items[StandNow]:GetAttribute("Owned")==true then
> NewUI:WaitForChild("Controls"):WaitForChild("Buy").Visible=false;
> if System.Items[StandNow]:GetAttribute("Equiped")==true then
> NewUI:WaitForChild("Controls"):WaitForChild("Unequip").Visible=true;
> NewUI:WaitForChild("Controls"):WaitForChild("Equip").Visible=false;
> else
> NewUI:WaitForChild("Controls"):WaitForChild("Unequip").Visible=false;
> NewUI:WaitForChild("Controls"):WaitForChild("Equip").Visible=true;
> end;
> else
> NewUI:WaitForChild("Controls"):WaitForChild("Buy"):WaitForChild("Button").Text="Buy";
> NewUI:WaitForChild("Controls"):WaitForChild("Buy").Visible=true;
> NewUI:WaitForChild("Controls"):WaitForChild("Unequip").Visible=false;
> NewUI:WaitForChild("Controls"):WaitForChild("Equip").Visible=false;
> end;
> end;
> coroutine.wrap(GetButton)();
> -- // On back
> NewUI:WaitForChild("Close"):WaitForChild("Button").MouseButton1Click:Connect(function()
> -- // Sound
> System.Sounds.Open:Play();
> -- // Get camera
> System.Services.Tween:Create(System.Services.Workspace.CurrentCamera,System.TweenInfo,{CFrame=OriginalCameraState}):Play();
> -- // Off UI
> NewUI:Remove();
> -- // Unlock character
> System.Character:WaitForChild("HumanoidRootPart",3).Anchored=false;
> -- // Remove stands
> for _,Stand in pairs(Stands) do
> if typeof(Stand)=="Instance" then
> pcall(function()
> Stand:Remove()
> end);
> end;
> end;
> -- // On core
> System.Services.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All,true);
> -- // On camera
> delay(.4,function()
> System.Services.Workspace.CurrentCamera.CameraType=Enum.CameraType.Custom;
> end);
> -- // Off shop
> delay(2,function()
> System.OnShop=false;
> end);
> end);
> -- // On equip
> NewUI:WaitForChild("Controls"):WaitForChild("Equip"):WaitForChild("Button").MouseButton1Click:Connect(function()
> coroutine.wrap(GetItem)(System.Items[StandNow]);
> NewUI:WaitForChild("Controls"):WaitForChild("Equip").Visible=false;
> NewUI:WaitForChild("Controls"):WaitForChild("Unequip").Visible=true;
> end);
> -- // On unequip
> NewUI:WaitForChild("Controls"):WaitForChild("Unequip"):WaitForChild("Button").MouseButton1Click:Connect(function()
> coroutine.wrap(RemoveItem)(System.Items[StandNow]);
> NewUI:WaitForChild("Controls"):WaitForChild("Equip").Visible=true;
> NewUI:WaitForChild("Controls"):WaitForChild("Unequip").Visible=false;
> end);
> -- // On right
> NewUI:WaitForChild("Control"):WaitForChild("Right"):WaitForChild("Button").MouseButton1Click:Connect(function()
> -- // Get math
> local NewStand=StandNow+1;
> -- // Check
> if NewStand<#System.Items or NewStand==#System.Items then
> -- // Give status
> StandNow=NewStand;
> -- // Get camera
> coroutine.wrap(UpdateCamera)();
> -- // Get button
> coroutine.wrap(GetButton)();
> -- // Update texts
> coroutine.wrap(UpdateText)();
> end;
> end);
> -- // On left
> NewUI:WaitForChild("Control"):WaitForChild("Left"):WaitForChild("Button").MouseButton1Click:Connect(function()
> -- // Get math
> local NewStand=StandNow-1;
> -- // Check
> if NewStand>0 then
> -- // Give status
> StandNow=NewStand;
> -- // Get camera
> coroutine.wrap(UpdateCamera)();
> -- // Get button
> coroutine.wrap(GetButton)();
> -- // Update texts
> coroutine.wrap(UpdateText)();
> end;
> end);
> -- // Buy
> NewUI:WaitForChild("Controls"):WaitForChild("Buy"):WaitForChild("Button").MouseButton1Click:Connect(function()
> -- // Sound
> System.Sounds.Buy:Play();
> -- // Check
> if System.Currency.Value>System.Items[StandNow]:WaitForChild("Cost").Value and System.Items[StandNow]:GetAttribute("Owned")==false then
> -- // Status
> System.Items[StandNow]:SetAttribute("Owned",true);
> -- // Server
> System.FireEvent:FireServer(StandNow,System.CurrencyName,System.Items[StandNow]:WaitForChild("Cost").Value);
> -- // Get button
> coroutine.wrap(GetButton)();
> -- // Texts
> coroutine.wrap(UpdateText)();
> else
> if NewUI:WaitForChild("Controls"):WaitForChild("Buy"):WaitForChild("Button").Text=="Buy" then
> NewUI:WaitForChild("Controls"):WaitForChild("Buy"):WaitForChild("Button").Text="Error";
> delay(2,function()
> NewUI:WaitForChild("Controls"):WaitForChild("Buy"):WaitForChild("Button").Text="Buy";
> end);
> end;
> end;
> end);
> end;
> end);
>
> > -- server
> Players=game:GetService("Players");
> Data=game:GetService("DataStoreService"):GetDataStore("portal");
> Storge=game:GetService("ReplicatedStorage");
> Key="_Score-";
> IndexName="ToolsIndex";
> StandartIndexValue=1;
> -- // On event
> Storge:WaitForChild("ToolsShop"):WaitForChild("BuyTool").OnServerEvent:Connect(function(User,Value,CostName,Costs)
> User:WaitForChild(tostring(IndexName),5).Value=math.floor(Value);
> -- // Found cost
> local Cost;
> for _,Object in pairs(User:GetDescendants()) do
> if typeof(Object)=="Instance" then
> if Object:IsA("ValueBase") then
> if Object.Name:lower()==CostName:lower() then
> Cost=Object;
> end;
> end;
> end;
> end;
> wait();
> -- // Check currency
> assert(typeof(Cost)=="Instance","Currency was not found");
> -- // Minimal
> if Cost.Value>Costs or Cost.Value==Costs then
> Cost.Value=Cost.Value-Costs;
> else
> User:Kick("error");
> end;
> end);
> -- // On Player added
> Players.PlayerAdded:Connect(function(Player)
> --
> local Index=Instance.new("NumberValue",Player);
> Index.Name=tostring(IndexName);
> --
> Index.Value=math.floor(StandartIndexValue);
> --
> Index:GetPropertyChangedSignal("Name"):Connect(function()
> if Index.Name~=tostring(IndexName) then
> Player:Kick("Unknow shop error")
> end;
> end);
> --
> pcall(function()
> coroutine.wrap(function()
> local Async=Data:GetAsync(Key..tostring(Player.UserId));
> --
> if Async then
> Index.Value=Async[1];
> end;
> end)();
> end);
> end);
> -- // On player leave
> Players.PlayerRemoving:Connect(function(Player)
> pcall(function()
> local Thread=coroutine.create(function()
> Data:SetAsync(Key..tostring(Player.UserId),{Player:FindFirstChild(tostring(IndexName)).Value});
> end);
> coroutine.resume(Thread);
> end);
> end);
> -- // On softdown
> game:BindToClose(function()
> for _,Player in pairs(Players:GetPlayers()) do
> pcall(function()
> local Thread=coroutine.create(function()
> Data:SetAsync(Key..tostring(Player.UserId),{Player:FindFirstChild(tostring(IndexName)).Value});
> end);
> coroutine.resume(Thread);
> end);
> end;
> end);
Are there any reasons why this may be occuring?
It’s impossible to read your code. Please only show the part with the error, and make it like this:
(without the spaces)
` ` `
paste code here
` ` `
Or, select the code and press the button.
Sorry i edited it now that should be better and as for the error there is no error but it just gives a free item without buying which i want to stop
anyone know how i can change it to so it doesn t give a free item