Hello, dear community members,
I’m currently working on a game called “Cookie Simulator”. In-game, players must collect cookies by stepping on them. When a player touches a cookie, they receive a cookie via the leaderstats. Each cookie (each part) has a script in it, and I heard that may because lags. Is there a way to only have one script so the cookies can work? Thanks for your help!
Here’s the script which is in all cookies (in all parts):
function onTouched(Hit)
if Enabled == false then
Enabled = true
local CheckHumanoid = Hit.Parent:FindFirstChild("Humanoid")
if CheckHumanoid then
local User = game.Players:GetPlayerFromCharacter(Hit.Parent) --get player from touching human
local Stats = User:findFirstChild("leaderstats")
Invisible()
if Stats then
local Cookies = Stats:findFirstChild("Cookies")
if MarketplaceService:UserOwnsGamePassAsync(User.UserId, GamepassId) then
Cookies.Value = Cookies.Value + CookieToAdd * 2
else
Cookies.Value = Cookies.Value + CookieToAdd * 1
end
end
wait(10)
Visible()
Enabled = false
end
end
end
Thanks for future help,
~ Arlenox!