Frog currency script not giving any currency

Hello!

So right now I am working on a friends game and I have made it so when you hit a frog, it will give you the currency which is “Frogs” (as well as a badge and then delete the part). So far I have 12 frogs set up and only 7 of them fully work. the remaining 5 do give you the badge, just do not give you the frog currency. I find this weird because everything is set up the same way using the same scripts but why is it that only just over half of them work? I have tried using a different collecting script but that did not work. There are a few different scripts set up for this whole thing to work.

Here are the ones I think are most important in this case:

This script gives the Frog currency (normal script in the meshpart)

amnt = 1 --how much you get for it
debounce = false
function onTouched(part)
	if debounce then return end
	debounce = true
	local h = part.Parent:findFirstChild("Humanoid")
	if (h~=nil) then
		local thisplr = game.Players:findFirstChild(h.Parent.Name)
		if (thisplr~=nil) then
			local leaderstatsstats = thisplr:findFirstChild("leaderstats")
			if (leaderstatsstats~=nil) then
				local frogs = leaderstatsstats:findFirstChild("Frogs")
				if (frogs~=nil) then
					wait(0.5)
					frogs.Value = frogs.Value + amnt
					wait(1)
					debounce = false
				end
			end
		end


	end
end

script.Parent.Touched:connect(onTouched)

This script is a script in ServerScriptService that when a player joins, it will check if the player owns the badge for that specific frog, and if they have it they will give the player a frog (using this way as a datastore)

local BadgeService = game:GetService("BadgeService")
local BadgeId = 2127627990

game:GetService("Players").PlayerAdded:Connect(function(player)
	if BadgeService:UserHasBadge(player.UserId, BadgeId) then
		player.leaderstats.Frogs.Value = player.leaderstats.Frogs.Value + 1
	end
end)

This last script is the script I get an error on for one of the frogs even though it shouldn’t give an error at all (it happens when the player touches the part) This script deletes the frog for that player only. It is a localscript in StarterGui (it still works though)

local LocalPlayer = game:GetService("Players").LocalPlayer
game.Workspace.FrogsFolder.WaterFrog.Touched:Connect(function(part)
	wait(0.25)
	if LocalPlayer.Character and part:IsDescendantOf(LocalPlayer.Character) then
		game.Workspace.FrogsFolder.WaterFrog:Destroy()
	end
end)

The error i get for this occurs multiple times even though WaterFrog is a valid member of the folder…

image

If anyone could help with this that would be really helpful because it is basically the most important part of this game. Thank you :slight_smile:

try this

local LocalPlayer = game:GetService("Players").LocalPlayer
game.Workspace.FrogsFolder.WaterFrog.Touched:Connect(function(part)
	wait(0.25)
	if LocalPlayer.Character and part:IsDescendantOf(LocalPlayer.Character) then
		game.Workspace.FrogsFolder:WaitForChild("WaterFrog"):Destroy()
	end
end)
1 Like

I think it got rid of the error but it still gives nothing

Probably your script. I cannot help anymore I’m on mobile. Sorry

no problem, thank you for the error though

I think most of your code is quite old. Can you update it?

How so is it old, and update it how? because as I did say I did try to update some but it didn’t work (the coin collection I know is old but idk about the rest of it)

You’ll need to remove deprecated functions like findFirstChild and replace them with FindFirstChild. That’s just one example.

Oh okay, I will try that in a little bit.

Just tried it, it did not work.

I didn’t say it would work. I’m just giving advice.

If WaterFrog does not exist how can it be touched?

1 Like

I have no clue, it does exist and I have no idea why it gives that error.

I would create a local script in start gui which handles every meshpart (frog) in the frog folder. Whenever a part is touched you get +1 amount, the touched frog destroys and you fire a remote event so you get the badge of the touched frog. You could add (for every frog) a IntValue with the badge Id. Also add a script which handles that when the player joins and it has the badge of one of the frogs then it destroys. You could just loop trough the frogs and check if the Id of one of the IntValues equals with one of the BadgeIds you added in a Table. I can send you some code later, however im on mobile rn so i cant really help any further.

Alright, got my hands on it and made a little system for you:

  1. Add a Remote Event into Replicated Storage and name it “Frog_Touched”
  2. Add an Int Value into every Frog “Mesh”-Part and name it “BadgeID”
  3. Change the Value to the BadgeID you would get if you touch this part
  4. Add a Script in ServerScriptService, name it “FrogHandler” and put following lines in it:
local Folder = workspace.FrogsFolder
local Event = game.ReplicatedStorage.Frog_Touched
local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")

Event.OnServerEvent:Connect(function(player, Amount, v) -- Event Handler
	if player and player.Name == Players:FindFirstChild(player.Name) then
		local leaderstats = player:WaitForChild("leaderstats")
		local Frogs = leaderstats:FindFirstChild("Frogs")
		local BadgeID = v:FindFirstChild("BadgeID").Value
		if leaderstats and Frogs and BadgeID then
			Frogs.Value = Frogs.Value + Amount
			if not BadgeService:UserHasBadgeAsync(player.UserId, BadgeID) then
				BadgeService:AwardBadge(player.UserId, BadgeID)
			end
		end
	end
end)


game.Players.PlayerAdded:Connect(function(player) -- Frog Destroy and Value Handler
	if player and player.Name == Players:FindFirstChild(player.Name) then
		local leaderstats = player:WaitForChild("leaderstats")
		local Frogs = leaderstats:FindFirstChild("Frogs")
		for i,v in pairs(Folder:GetChildren()) do
			if v:IsA("Part") or v:IsA("MeshPart") or v:IsA("BasePart") or v:IsA("UnionOperation") and v.CanTouch and v.BadgeID then
				local BadgeID = v:FindFirstChild("BadgeID").Value
				if BadgeService:UserHasBadgeAsync(player.UserId, BadgeID) then
					v:Destroy()
					Frogs.Value = Frogs.Value + 1
				end
			end
		end
	end
end)

These lines firstly handle the function when you found a new frog (award badge, +1 Frog in leaderstats) AND they handle the function when the player joined the game (Script checks if player owns any of the Badges (compares BadgeID’s with your owned Badges) and if the result is == true the Part with the owned BadgeID destroys and the player gets +1 frog)
5. add a local script in StarterGui and name it how you want. Now add these lines in it:

local Amount = 1 --how much you get for it
local debounce = true
local Event = game.ReplicatedStorage.Frog_Touched
local Folder = workspace.FrogsFolder

for i,v in pairs(Folder:GetChildren()) do
	if v:IsA("Part") or v:IsA("MeshPart") or v:IsA("BasePart") or v:IsA("UnionOperation") and v.CanTouch then
			v.Touched:Connect(function(hit)
			if debounce then 
				debounce = false
				local Humanoid = hit.Parent:FindFirstChild("Humanoid")
				if Humanoid then
					if game.Players:FindFirstChild(Humanoid.Parent.Name) == game.Players.LocalPlayer.Name then
						wait(0.5)
						Event:FireServer(Amount, v)
						wait(1) -- important!
						v:Destroy()
						debounce = true
					end
				end
			end
		end)
	end
end

The local script checks (when a part of the folder is touched) if the Player is a real Player and fires the Remote Event. Since you only can add Values Server-Sided this is necessary.

NOTE: nothing will work if you don’t follow the steps! Also, if anything is not working right pls tell me (did not test the scripts)!

Hope I could help! (took me some time to make ^^)

Did you try it out yet. Its been 2 weeks with no reply yet…