Hello everyone, so i made a 2x boost where if a player touches one button, he will get the doubled value, but this is not working,
there are 3 boost: 2x,3x,5x
local Players = game:GetService("Players")
local Button = script.Parent.redbutton
local particle = Button.ParticleEmitter
local ActivePlayers = {}
--// ^ table for storing players that are near the button.
task.spawn(function()
while true and task.wait(0.07) do
for i,v in pairs(Players:GetChildren()) do
--// ^ loop trough all the players in game
if (v.Character) and (v.Character:FindFirstChild("HumanoidRootPart")) then
--// ^ check if their character and humanoidrootpart exists so we can check how far away from the button they are.
local Root = v.Character.HumanoidRootPart
if (Root.Position - Button.Position).Magnitude <= 4 and (not table.find(ActivePlayers, v.Name)) then
--// ^ magnitude is basically how far away the 2 positions are apart, so we are checking if the humanoidrootpart is less than 6 studs away from the button, we are also checking if the player is not already in the ActivePlayers.
table.insert(ActivePlayers, v.Name)
particle.Enabled = true
--// ^ add the player to the ActivePlayers table
elseif (Root.Position - Button.Position).Magnitude > 4 and (table.find(ActivePlayers, v.Name)) then
--// ^ if the if statement above doenst run then we check if the player is more than 6 studs away from the button and if they are in the ActivePlayers table.
table.remove(ActivePlayers, table.find(ActivePlayers, v.Name))
particle.Enabled = false
--// ^ if they are far away and in the table then we just remove them.
end
end
if (table.find(ActivePlayers, v.Name)) then
--// ^ if the player is in the table then we add cash their value.
local get2x = v:FindFirstChild("ButtonsFolder"):FindFirstChild("Cash2x")
local get3x = v.ButtonsFolder.Cash3x.Value
local get5x = v.ButtonsFolder.Cash5x.Value
print(get2x.Value)
print(get3x)
print(get5x)
local Coins = v.leaderstats.Cash
Coins.Value += 1
print(Coins.Value)
end
end
end
end)
all boost value is 1 but still it is showing 0 and btw it is a value that is stored in player!