Hello!
I want to create my own egg hatching system and my own simulator with that system in, but, there has occured some bugs.
Let me explain the plan of the system:
- purchase gui trigger
- triggering main purchase script in ServerScriptService with sending some information like level
- check if level >= requiring level
- if check has completed successfully, system will trigger main purchase module
- module’s randomizer triggered
- return randomized choice of main purchase module
- (for now) printing pet’s name
So, you might ask me:
What is the problem?
There it is:
Purchase system is saying pet’s names twice or three times in a row without a delay.
First line is saying that everything is normal and pet’s name printed only once.
Second is saying “hey dude you pressed three times without a delay hahahaha live with it” and its repeating.
I tried to put cooldown in the gui, in the purchase script, but nothing helped me.
Gui script:
local text = script.Parent.Main
local yes = script.Parent.bg_yes.Yes
local no = script.Parent.bg_no.No
local rep = game:GetService('ReplicatedStorage')
local event = rep.ClientEvents.PurchaseGuiCall
local event2 = rep.FCTSEvents.PurchaseCall
local types = {
['Classic'] = {
['LvlReq'] = 1;
['Cost'] = 150;
['Text'] = "Are you sure you want to buy the Classic sphere for 150$?";
};
}
local plr = game.Players.LocalPlayer
local deb = false
event.OnClientEvent:Connect(function(callType)
if deb == false then
deb = true
local ct = types[callType]
script.Parent.Visible = true
if ct ~= nil then
text.Text = ct.Text
yes.MouseButton1Click:Connect(function()
event2:FireServer({pt = 'Spheres',sphere='classic',lvl=ct.LvlReq,cost=ct.Cost})
script.Parent.Visible = false
end)
no.MouseButton1Click:Connect(function()
script.Parent.Visible = false
end)
else
script.Parent.Visible = false
end
wait(1)
deb = false
end
end)
Purchase script:
local rep = game:GetService('ReplicatedStorage')
local events = rep.FCTSEvents
local event = events.PurchaseCall
local ss = game:GetService('ServerScriptService')
local modules = ss.modules
local noobsgiver = modules.noobsgiver
event.OnServerEvent:Connect(function(plr,info)
local purchasetype = info.pt
if purchasetype == 'Spheres' then
local sph = info.sphere
local cost = info.cost
local lvl = info.lvl
wait(0.01)
local value = plr.leaderstats.Cash
local value2 = plr.leaderstats.Level
if value2.Value < lvl then
plr:Kick('suspicious purchase event call, possibly using cheats')
end
value.Value -= cost
local module = require(noobsgiver[sph])
local noob = module.noobgiver()
print(noob.Name)
end
end)
Purchase module:
local module = {}
local noobs = game:GetService('ServerScriptService').noobs.classic
local epic = noobs.Epic
local uncommon = noobs.Uncommon
local common = noobs.Common
module.noobs = {
['Epic'] = {
epic.CubicNoob;
};
['Uncommon'] = {
uncommon.NegatiGhostyNoob;
uncommon.GhostyNoob;
};
['Common'] = {
common.NegatiNoob;
common.ClassicNoob;
}
}
module.rarity = {
['Epic'] = 0.5;
['Uncommon'] = 14.5;
['Common'] = 85;
}
module.noobgiver = function()
local rand = math.random(1,100) -- generate number of chance for each rarity (ex.: if rand = 0.5 then system will give random epic pet)
local cout = 0
for r, w in pairs(module.rarity) do -- r = rarity, w = for counter
cout = cout + w
if rand <= cout then
local rTab = module.noobs[r]
local noob = rTab[math.random(1,#rTab)]
return noob
end
end
end
return module
I dont think there was a mistake in the scripts, please someone respond
P.S: by the way, dont ask me why the time is 09:09 AM, and im making this topic at 18:32 PM, its just because my pc sometimes have errors with the time