i want a player to get a tool when he reaches a amount of Coins
This doesnt work
game:GetService(“Players”).PlayerAdded:Connect(function(player)
local billboardgui = game:GetService(“ServerStorage”):WaitForChild(“BillboardGui”)
player.CharacterAdded:Connect(function(players)
if players.Head:FindFirstChild(“BillboardGui”) then
else
local clonedgui = billboardgui:Clone()
while true do wait()
local Tool = script.VoidScythe -- REPLACE GravityCoil WITH THE NAME OF YOUR TOOL
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
if Player.leaderstats.TimeAlive.Value == 15000 then
local ToolClone = Tool:Clone()
ToolClone.Parent = Player.Backpack
end
end)
end)
if player.MembershipType == Enum.MembershipType.Premium then
player.PlayerGui.Premium.ImageButton.Visible = true
clonedgui.TextLabel.ImageLabel.Visible = true
wait(5)
end
if player.Character:FindFirstChild("Head") ~= nil then
clonedgui.TextLabel.Text = player.leaderstats.TimeAlive.Value
local Head = player.Character.Head
clonedgui.TextLabel.TextColor3 = Color3.fromRGB(236,236,236)
clonedgui.Parent = game.Workspace:WaitForChild(player.Name).Head
end
end
end
end)
Do you have any errors? Also for one of your CharacterAdded() events you used “players” as a parameter instead of “character”. Not sure if it cares though, I never did anything other than “character”.
I wrote something that might help you, but unfortunately was unable to test it.
Please, give it a shot and see if it works. If it does not work, make sure to include the console logs, okay?
local players = game:GetService("Players")
local toolsStorage = script -- Set the path to where you are storing tools here
local toolsList = { -- Very basic system, you add a tool name alongside its required value, you can have multiple here
["VoidScythe"] = 15000, -- VoidScythe will be given once the player reaches 15k
["AnotherTool"] = 15001 -- No comma here since it is the last tool of the list
}
function giveTool(player, toolName, noDuplicates)
-- noDuplicates == true means that the player won't be given tools they already have
-- noDuplicates == false or nil means that the player will be given repeated tools
local backpack = player.Backpack
if noDuplicates and backpack:FindFirstChild(toolName) then
-- The player already have this tool, so don't give it to them
return
end
local toolObject = toolsStorage:FindFirstChild(toolName)
if toolObject then
toolObject:clone().Parent = backpack
else
warn(string.format("Tool %s not found!", toolName))
end
end
function validateTools(player, timeAlive)
for toolName, valueRequired in next, toolsList do
if timeAlive >= valueRequired then
giveTool(player, toolName, true)
end
end
end
players.PlayerAdded:connect(function(player)
local leaderstats = player:WaitForChild("leaderstats")
local timeAlive = leaderstats:WaitForChild("TimeAlive")
-- Time alive means that every second the value changes, right?
-- If so, then the best approach would be to check every second, instead of every wait()
-- This should help with avoiding unnecessary lag
timeAlive:GetPropertyChangedSignal("Value"):connect(function(newValue)
validateTools(player, newValue)
end)
end)
To give a weapon to players on exactly 15000 you put their value == 15000
To give a weapon to players on more than 15000 you put their value >= 15000
To give a weapon to players on less than 15000 you put their value <= 15000
To give a weapon to players who have any value except 15000 you put their value ~= 15000
Your error is that you expect their value to be exactly (==) 15000
when it should be greater (>=) than 15000 (and possibly end once its less than let’s say 25000), another error that could be happening is that the code ran, but now it ignores whatever is happening after. Why? Because it already ran the code. Try using .changed on your script or :getattributechangedsignal, I don’t know if it’s the best decision but perhaps it works.
Is there a limit to how much value the person needs to have until they no longer have the weapon? Like, is the weapon only when the player has more than 15000 and less than 25000 or something? I believe no…
I need to ask some questions.
First one I already said it above this text, you would have to add “and player.leaderstats.timealive.value < 25000” to it
Second, have you tried utilizing print statements to check if that part of code is running? In case you didn’t know, print statements can be used to check if a line of code reaches a certain moment in the script. Because you need the if statement to be true to run the code inside you can put a print inside the if statement and see if it says that print line in the command box, if it does print then it’s working, if it doesn’t then there’s something wrong inside it. It’s a method of debugging.
Third. Does it give the tool sometimes?
Fourth. If the tool is necessary from one point afterwards, have you tried making the script make a quick check to see if they have a number high enough to be worthy of the tool?