-
Subtracting value from what ever number is in textbox
-
Script won’t work
persontarg.leaderstats.Money.Value = persontarg.leaderstats.Money.Value - tonumber(wait1.Text)
Subtracting value from what ever number is in textbox
Script won’t work
persontarg.leaderstats.Money.Value = persontarg.leaderstats.Money.Value - tonumber(wait1.Text)
Is there only a value in there or is it some normal text aswell?
There is a value in leaderstats but not for the textbox
Run this and see what it prints okay
if tonumber(wait1.Text) ~= nil then
print("Number")
else
print("Can't become number")
end
Doesn’t print anything… Why would it not?
That is weird because if it had printed “Number” then it would have been a number, if it would have printed “Can’t become number” then it would have been some string characters in there. But printing nothing is weird…
Here’s the server script
folder.confirm.OnServerEvent:Connect(function(player,Target,persontarg,wait1)
print("Recieved")
print("yes")
persontarg.Character.FineValue.Value = false
player.PlayerGui.FineGui.Frame.Visible = false
if tonumber(wait1.Text) ~= nil then
print("Number")
else
print("Can't become number")
end
persontarg.leaderstats.Money.Value = persontarg.leaderstats.Money.Value - tonumber(wait1.Text)
local MessageData = {
["content"] = persontarg.Name.." was arrested by "..player.Name
}
MessageData = HS:JSONEncode(MessageData)
HS:PostAsync(WebhookURL,MessageData)
end)
And local script
local player = game.Players.LocalPlayer
local players = game.Workspace:WaitForChild("Players")
local rs = game:GetService("ReplicatedStorage")
local folder = rs:WaitForChild("remotes")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
function Open()
local Character = LocalPlayer.Character
local HumanoidRootPart = Character and Character:FindFirstChild("HumanoidRootPart")
if not (Character or HumanoidRootPart) then return end
local TargetDistance = 8
local Target
for i,v in ipairs(Players:GetPlayers()) do
if v ~= LocalPlayer and v.Character and v.Character:FindFirstChild("HumanoidRootPart") then
local TargetHRP = v.Character.HumanoidRootPart
local mag = (HumanoidRootPart.Position - TargetHRP.Position).magnitude
if mag < TargetDistance then
TargetDistance = mag
Target = v
print(Target.Name)
print("Fired")
local persontarg = game.Players[Target.Name]
local wait1 = script.Parent.Parent.time
if wait1.Text == "" then
else
print("actually fired")
folder.confirm:FireServer(player,Target,persontarg,wait1)
end
end
end
end
end
script.Parent.MouseButton1Down:Connect(Open)
Where did you get the wait1 object from?
Edit: NVM, found it
I don’t think you need to call the player there because that will automatically come in the server sided script
That can’t be the reason why it isn’t working though
Yeah true but it is worth testing every solution that it could be you know, because I have no idea either
I’m assuming you want to subtract value from a number using a Textbox:
local numb = tonumber(wait1)
persontarg.leaderstats.Money.Value -= numb
print(persontarg.leaderstats.Money.Value)
Didn’t work. I’ve noticed if I put this at the top, nothing below it works.
The text from the textbox isn’t being replicated to the server (which is intentional), you need to run the text value (not the instance) through a remote event first.
ReplicatedStorage.SubtractMoney:FireServer(TextBox.Text)
ReplicatedStorage.SubtractMoney.OnServerEvent:Connect(function(p, moneyToSubtract)
local validatedMoney = tonumber(moneyToSubtract)
if not validatedMoney then return end
p.leaderstats.Money.Value -= validatedMoney
end)
Where did you get money to subtract
Sometimes calling variables outside the function will store that one variable in a specific state. Now if you change that value without updating the variable, it will always return the same thing.
So basically if you have a variable that should be updated every use-case, put it inside the function instead of making it global. You should see the problem go away.
Also another good thing to note is this:
myValue = script.Parent.NumberValue.Value -- stores the current value in a variable which is most likely 0.
myValue = myValue + 1 -- this will only update the variable, and not the actual value object.
So in most cases, you want to do this:
myValue = script.Parent.NumberValue -- only get the object
myValue.Value = myValue.Value + 1 -- now this will correctly add onto the value
Hope this sort of helped. I didn’t read through this all because I’m tired and my brain hurts but I think this is related in some form.