Good Evening! (or morning/afternoon)
Tonight I am working on saving a currency by using badges.
How this works is, when the player hits the part, it gets deleted and they are given the currency. When they leave there is a script that will check if the player owns the badge for that part, if they do it will give them the currency and delete the part. This rejoining part does not seem to work. (doesnt delete the part or give the currency) The script is in a folder in ServerScriptService, and it is a normal script (should be a local script because it has to delete the part but I was seeing if it would work as a normal one).
Here is the script!
local BadgeService = game:GetService("BadgeService")
local BadgeId = 2126944041
game:GetService("Players").PlayerAdded:Connect(function(player)
if BadgeService:UserHasBadge(player. UserId, BadgeId) then
game.Players.leaderstats.Frogs.Value = game.Players.leaderstats.Frogs.Value + 1
game.Workspace.FrogsFolder.RegularFrog:Destroy()
end
end)
If anyone could help fix this that would be great! I swear I did this right no idea what is wrong
local BadgeService = game:GetService("BadgeService")
local BadgeId = 2126944041
game:GetService("Players").PlayerAdded:Connect(function(player)
if BadgeService:UserHasBadge(player.UserId, BadgeId) then -- fixed spacing on Player.Userid here
player.leaderstats.Frogs.Value = player.leaderstats.Frogs.Value + 1 -- needed to use player here to reference not game.Players
game.Workspace.FrogsFolder.RegularFrog:Destroy()
end
end)
local BadgeService = game:GetService("BadgeService")
local BadgeId = 2126944041
local Player = game.Players.LocalPlayer
if BadgeService:UserHasBadge(Player.UserId, BadgeId) then -- fixed spacing on Player.Userid here
game.Workspace.FrogsFolder.RegularFrog:Destroy()
end
and on that server script you have to just remove the destroy line and it will still add +1
you could create a remote event & fire it to the specific player like so :
local BadgeService = game:GetService("BadgeService")
local BadgeId = 2126944041
game:GetService("Players").PlayerAdded:Connect(function(player)
if BadgeService:UserHasBadge(player.UserId, BadgeId) then
player.leaderstats.Frogs.Value = player.leaderstats.Frogs.Value + 1 -- needed to use player here to reference not game.Players
game.ReplicatedStorage.RemovePart:FireClient(player)
end
end)
and in the localscript :
local Player = game.Players.LocalPlayer
game.ReplicatedStorage.RemovePart.OnClientEvent()
game.Workspace.FrogsFolder.RegularFrog:Destroy()
end)
no you can put this in the startergui in a local script or even in StarterPlayerScripts but i normally do startergui from old habit and it reloads those when character reloads