After More Than 24 Hours Im Still Confused And This Is What Is Stopping Me From Finishing This.
I Have A Script In Workspace That Makes A Leaderboard Stat Named Candy
Here Is A Snipet For Example Its Related To Trick Or Treating.
local candy = p.leaderstats.Candy.Value
local houses = playersHouses[p]
pcall(function()
ds:SetAsync(p.UserId, {candy, houses})
end)
end
game.Players.PlayerAdded:Connect(function(p)
local ls = Instance.new("Folder", p)
ls.Name = "leaderstats"
local candy = Instance.new("IntValue", ls)
candy.Name = "Candy"
local candyData = 0
local housesData = {}
Anyways Now There Is A Candy Leader stat And I Want To Grant A Badge At Certain Candy Amounts.
Also it must be where it can go past the number and they still get the badge.
At 750 Candies — 2124857939
At 2500 Candies — 2124857942
At 5000 Candies — 2124857941
What do i do ?
This Is My Current Code But Makes No Sense And I Dont know how to add several ids onto this or do i duplicate the script several times to add more Ids ?. Is This Working
local First: Value here -- ID of the Badge
local Second: Value here
local Third: ANother value here
candy.Changed:Connect(function(newVal)
if newVal >= 750 then --- Award first Badge
badges:AwardBadge(player.UserId, First)
else if newVal >= 2500 then -- Award the Second badge
badges:AwardBadge(player.UserId, Second)
else if newVal >= 2500 then -- Award the Third badge
badges:AwardBadge(player.UserId, Third)
end
end
end
I made it a server script service script and it didnt work
i lowered it down to 46 candies so i would have the same amount and none was granted.
also i changed Candy And candy and tried both.
Variables are something kinda personal, you choose your Reference (Variable Name)… i can’t really help with that
Candy = Something
Cand = OtherThing
Can = SomethingElse
whatever, really depends…
In the end variables are just a reference, don’t forget that
for Example
local CandyVariable = Instance.new("IntValue", player)
CandyVariable.Name = "Candy"
CandyVariable.Value = 0
See, CandyVariable is a Variable, but the Intvalue i called by another name so
you must acess the Intvalue.Value to work
Ex:
player.Candy.Value
it didnt work again
Ignore coins
this is what i mean by Candy
when it hits 46 or whatever number i want it to grant a badge
then 47 another
then 48 another
the code didnt work it says there are syntax errors though located in image 2
Image 1 Above
Image 2 Below
the player And Candy + badges text is red underlighted. you cant screenshot it.
This code handles the trick or treating system and the candy leaderboard
how do i make it work for this script ?
local dss = game:GetService(“DataStoreService”)
local ds = dss:GetDataStore(“TrickOrTreat”)
local playersHouses = {}
function saveData(p)
local candy = p.leaderstats.Candy.Value
local houses = playersHouses[p]
pcall(function()
ds:SetAsync(p.UserId, {candy, houses})
end)
end
game.Players.PlayerAdded:Connect(function(p)
local ls = Instance.new("Folder", p)
ls.Name = "leaderstats"
local candy = Instance.new("IntValue", ls)
candy.Name = "Candy"
local candyData = 0
local housesData = {}
pcall(function()
local data = ds:GetAsync(p.UserId)
candyData = data[1]
housesData = data[2]
end)
playersHouses[p] = housesData
candy.Value = candyData
end)
game.Players.PlayerRemoving:Connect(saveData)
game:BindToClose(function()
for i, p in pairs(game.Players:GetPlayers()) do
spawn(saveData(p))
end
end)
for i, house in pairs(script.Parent:GetChildren()) do
if house:IsA("Model") and house:FindFirstChild("Doorbell") then
local doorOpen = false
local cd = house.Doorbell.ClickDetector
cd.MouseClick:Connect(function(p)
if not table.find(playersHouses[p], house.Name) and not doorOpen then
doorOpen = true
local character = game.Players:GetPlayers()[math.random(1, #game.Players:GetPlayers())].Character
character.Archivable = true
character = character:Clone()
character:SetPrimaryPartCFrame(house.Door.CFrame - house.Door.CFrame.LookVector * 2)
wait(math.random(1, 3))
character.Parent = workspace
local cf = house.Door.CFrame
house.Door.CFrame = cf * CFrame.Angles(0, math.rad(90), 0) + (cf.LookVector * house.Door.Size.X/2) + (cf.RightVector * house.Door.Size.X/2)
p.leaderstats.Candy.Value += 1
wait(5)
house.Door.CFrame = cf
character:Destroy()
table.insert(playersHouses[p], house.Name)
doorOpen = false
end
end)
end
Candy.Changed:Connect(function(newVal)
if newVal >= 750 then --- Award first Badge
badges:AwardBadge(player.UserId, First)
else if newVal >= 2500 then -- Award the Second badge
badges:AwardBadge(player.UserId, Second)
else if newVal >= 2500 then -- Award the Third badge
badges:AwardBadge(player.UserId, Third)
end
end
end
end) ---------------- Close the Function ( This was Missing )
local First = 2124855570 – ID of the Badge
local Second = 2124849605
local Third = 2124703048
Candy.Changed:Connect(function(newVal)
if newVal >= 46 then — Award first Badge badges:AwardBadge(player.UserId, First)
else if newVal >= 46 then -- Award the Second badge
**badges**:AwardBadge(**player**.UserId, Second)
else if newVal >= 46 then -- Award the Third badge
**badges**:AwardBadge(**player**.UserId, Third)
end
end
end
IF BOLD = HIGHLIGHTED RED OR HAS A ******** Around It
Would this work ? and give all badges if i had 46 candies ?
Would this work ? also with the trick or treat handler ?
Would it work with this script ?
local dss = game:GetService(“DataStoreService”)
local ds = dss:GetDataStore(“TrickOrTreat”)
local playersHouses = {}
function saveData(p)
local candy = p.leaderstats.Candy.Value
local houses = playersHouses[p]
pcall(function()
ds:SetAsync(p.UserId, {candy, houses})
end)
end
game.Players.PlayerAdded:Connect(function(p)
local ls = Instance.new("Folder", p)
ls.Name = "leaderstats"
local candy = Instance.new("IntValue", ls)
candy.Name = "Candy"
local candyData = 0
local housesData = {}
pcall(function()
local data = ds:GetAsync(p.UserId)
candyData = data[1]
housesData = data[2]
end)
playersHouses[p] = housesData
candy.Value = candyData
end)
game.Players.PlayerRemoving:Connect(saveData)
game:BindToClose(function()
for i, p in pairs(game.Players:GetPlayers()) do
spawn(saveData(p))
end
end)
for i, house in pairs(script.Parent:GetChildren()) do
if house:IsA("Model") and house:FindFirstChild("Doorbell") then
local doorOpen = false
local cd = house.Doorbell.ClickDetector
cd.MouseClick:Connect(function(p)
if not table.find(playersHouses[p], house.Name) and not doorOpen then
doorOpen = true
local character = game.Players:GetPlayers()[math.random(1, #game.Players:GetPlayers())].Character
character.Archivable = true
character = character:Clone()
character:SetPrimaryPartCFrame(house.Door.CFrame - house.Door.CFrame.LookVector * 2)
wait(math.random(1, 3))
character.Parent = workspace
local cf = house.Door.CFrame
house.Door.CFrame = cf * CFrame.Angles(0, math.rad(90), 0) + (cf.LookVector * house.Door.Size.X/2) + (cf.RightVector * house.Door.Size.X/2)
p.leaderstats.Candy.Value += 1
wait(5)
house.Door.CFrame = cf
character:Destroy()
table.insert(playersHouses[p], house.Name)
doorOpen = false
end
end)
end