Still Struggling
The Code
This Code Opens A Trick Or Treat Door when you click a doorbell then you get candy
when you get 80 candy you get a badge.
badges are not being granted
anyone see the error ?
local ServerScriptService = game:GetService(“ServerScriptService”)
local RS = game:GetService(“ReplicatedStorage”)
local Players = game:GetService(“Players”)
local DataStore2 = require(5519945290) – This is the ID of you place
DataStore2.Combine(“DATA”, “Candies”)
local badges = game:GetService(“BadgeService”)
local FirstId = 2124857939-- ID of the Badge
local SecondId = 2124857941
local ThirdId = 2124857942
game.Players.PlayerAdded:Connect(function(player)
local CandyStore = DataStore2("Candies", player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local CandiesVariable = Instance.new("IntValue", leaderstats)
CandiesVariable.Name = "Candy"
CandiesVariable.Value = CandyStore:Get(0)
wait(1)
if CandyStore:Get() ~= nil then
print"Candies Exist in Data"
CandiesVariable.Value = CandyStore:Get(CandiesVariable)
else
print"Player had no Old Data"
CandiesVariable:Set(0)
end
local function CandyChanged(ChangedC) -- A vida
CandiesVariable.Value = CandyStore:Get(ChangedC)
print"Candy Value Changed"
end
CandyChanged()
CandyStore:OnUpdate(CandyChanged)
wait(1)
player:WaitForChild("leaderstats").Candy:GetPropertyChangedSignal("Value"):Connect(function()
print(player.Name .. "Received Candy")
print("Total Candies:" .. player.leaderstats.Candy.Value)
if player.leaderstats.Candy.Value >= 90 and player.leaderstats.Candy.Value < 10001 then --- If the Amount of Candies is Highter than 750.... Then
badges:AwardBadge(player.UserId, FirstId)
print"Received badge X 3"
else if player.leaderstats.Candy.Value >= 2500 and player.leaderstats.Candy.Value < 10001 then -- Award the Second badge
badges:AwardBadge(player.UserId, SecondId)
print"Received badge Y 5"
else if player.leaderstats.Candy.Value >= 5000 then -- Award the Third badge
badges:AwardBadge(player.UserId, ThirdId)
print"Received badge 10 Z"
end
end
end
end) ---------------- Close the Function
end)
for i, house in pairs(game.Workspace.HousesFolder:GetChildren()) do
if house:IsA("Model") and house:FindFirstChild("Doorbell") then
local doorOpen = false
local HouseButton = house.Doorbell.ClickDetector
HouseButton.MouseClick:Connect(function(p)
local CandyStorePlus = DataStore2("Candies", p)
if doorOpen == true then
print"You already Opened This Door..."
return
end
if doorOpen == false then
doorOpen = true
wait(1)
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)
wait(1)
print"Hello Dude, take this candy"
CandyStorePlus:Increment(4)
wait(4)
house.Door.CFrame = cf
wait(10)
doorOpen = false
print"The Cooldown Ended, you can open this door again"
end
end)
end
end