I have a script to drop 1/3 cash of player on death, but when I test it the player will drop less cash then expected, and that same cash wont add up to what the player had before
Pay attention to leaderstats in video
script
script.Parent.Humanoid.Died:Connect(function(hit)
local player = game.Players:FindFirstChild(script.Parent.Name)
local cln = game.ServerStorage.Dollar:Clone()
cln.Parent = workspace
cln.Position = script.Parent.Head.Position
cln.Worth.Value = player.leaderstats.Money.Value/3
print(cln.Worth.Value.." Money")
cln.Worth.Value = math.ceil(cln.Worth.Value)
print(player.leaderstats.Money.Value.." Before")
player.leaderstats.Money.Value = player.leaderstats.Money.Value/3
print(math.ceil(player.leaderstats.Money.Value/3) .."/3")
player.leaderstats.Money.Value = math.ceil(player.leaderstats.Money.Value)
end)
2 Likes
DasKairo
(Cairo)
June 29, 2023, 9:20am
#2
1/3 is a repeating number of 0.333333333…
You are using math.ceil()
to move towards the next whole number (0.33333... -> 1
)
1 Like
but how do i make it drop 1/3 of the players cash but still a whole number
DasKairo
(Cairo)
June 29, 2023, 9:29am
#4
With small numbers like this you can’t, you can only move up or move down when wanting to convert them into an integer, The closest you will get to a number being an Integer is 3, with 3/3 being 1, after that it will contain a Decimal until you reach 6, where 6/3 is 2, and so on, Integers will appear everytime you hit a number when skip counting towards 3, otherwise it will always contain a decimal, so its your choice on how exactly you want to handle it.
1 Like
okay i will try to find different methods and see if they work
Kyl3ST
(Kyl3ST)
June 29, 2023, 9:35am
#6
maybe try this see if it fix the issue of your function
script.Parent.Humanoid.Died:Connect(function(hit)
local player = game.Players:FindFirstChild(script.Parent.Name)
local cln = game.ServerStorage.Dollar:Clone()
cln.Parent = workspace
cln.Position = script.Parent.Head.Position
cln.Worth.Value = math.ceil(player.leaderstats.Money.Value/3)
print(cln.Worth.Value .. " Money")
cln.Worth.Value = math.ceil(cln.Worth.Value)
print(player.leaderstats.Money.Value .. " Before")
player.leaderstats.Money.Value = player.leaderstats.Money.Value - player.leaderstats.Money.Value/3
print(player.leaderstats.Money.Value .. "/3")
player.leaderstats.Money.Value = math.ceil(player.leaderstats.Money.Value)
end)
1 Like
oh i just fixed it by editing some things but this is my new script
script.Parent.Humanoid.Died:Connect(function(hit)
local player = game.Players:FindFirstChild(script.Parent.Name)
local cln = game.ServerStorage.Dollar:Clone()
cln.Parent = workspace
cln.Position = script.Parent.Head.Position
cln.Worth.Value = player.leaderstats.Money.Value/3
cln.Worth.Value = cln.Worth.Value
player.leaderstats.Money.Value = player.leaderstats.Money.Value - player.leaderstats.Money.Value/3
player.leaderstats.Money.Value = player.leaderstats.Money.Value
print(cln.Worth.Value.." Money")
end)
edit: i think it was actually because i converted the leaderstats value to a numbervalue instead of intvalue
system
(system)
Closed
July 13, 2023, 9:41am
#8
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.