Hello, so I am currently trying to code a script where when a player presses a button, then it will fire a remote event to the server and check if the player has enough money, if they have the item, and if they have a bool value in a folder that I made. The problem is that when the player presses the button, it takes away double the amount it needs to. For example, if I want to take away $50, it takes away $100. Here's the code:
-- Local Script local repStorge = game.ReplicatedStorage local RE = repStorge:WaitForChild("RemoteEvent") script.Parent.TextButton.MouseButton1Click:Connect(function() RE:FireServer("dfds5f4df165fds4f") end) --Server-Script local repStorge = game.ReplicatedStorage local RE = repStorge:WaitForChild("RemoteEvent") local Halos = {game.ServerStorage.Halo, game.ServerStorage.CartoonyHalo} game.Players.PlayerAdded:Connect(function(plr) local EquippedHalos = Instance.new("Folder", plr) EquippedHalos.Name = "EquippedHalos" end) RE.OnServerEvent:Connect(function(plr, key) if key == "dfds5f4df165fds4f" then local Halo = game.ServerStorage:WaitForChild("Halo") local char = plr.Character local money = plr.leaderstats.Money local EqHalo = plr:WaitForChild("EquippedHalos") -- Variable's local function checkFol() for _, halo in pairs(Halos) do for _, v in pairs(EqHalo:GetChildren()) do if EqHalo:FindFirstChild(halo.Name) then return true else return false end end end end local function checkForHalo() if char:FindFirstChild("Halo") then return true else return false end end local hasHaloOrNot = checkForHalo() local hHON = checkFol() if money.Value >= 20 and not hasHaloOrNot and not hHON then local ClonedHalo = Halo:Clone() for _, v in pairs(Halos) do money.Value = money.Value - 20 if not plr.EquippedHalos:FindFirstChild(v.Name) and ClonedHalo.Parent ~= char and plr.EquippedHalos:GetChildren().Name ~= v.Name then print("Working!") local NormalHalo = Instance.new("BoolValue", plr:FindFirstChild("EquippedHalos")) NormalHalo.Name = "Halo" ClonedHalo.Parent = char break end end end end end)
Please always feel free to comment something that I missed or a solution to this problem that I am facing. Have a great rest of your morning / day / night!