You can write your topic however you want, but you need to answer these questions:
When I touch this crystal, you get 1 crystal stat, the crystal removes itself, and it subtracts one from the starting value
When I touch a crystal, it gives a random amount, I tried adding a debounce but its not working.
https://gyazo.com/0d8228dbb2b1301a1ff7570f8052b408
There are 3 scripts to this system:
Server Remote Fire (Local, starter player scripts)
local plot = game:GetService("Workspace"):WaitForChild("Plot")
local debounce = false
local waittime = 5
while task.wait(0.1) do
for _, crystal in pairs(plot:GetChildren()) do
if crystal.Name == "BasicCrystal" then
crystal.Prim.Touched:Connect(function(PartTouched)
if PartTouched.Parent.Name == game.Players.LocalPlayer.Name then
debounce = true
game.ReplicatedStorage.Remotes.CrystalTouchNormal:FireServer(game.Players.LocalPlayer)
crystal:Destroy()
task.wait(waittime)
debounce = false
end
end)
end
end
end
Crystal Giver (Server, serverscriptservice)
game.ReplicatedStorage.Remotes.CrystalTouchNormal.OnServerEvent:Connect(function(plr)
local crystal = plr:WaitForChild("Data"):WaitForChild("Runes"):WaitForChild("NormalCrystal")
crystal.Value += 1
game.ReplicatedStorage.Remotes.CrystalRemove:FireClient(plr)
end)
Crystal Spawner (Local, starterplayerscripts)
local plot = game.Workspace:WaitForChild("Plot")
local crystals = game.ReplicatedStorage.Crystals
local luck = require(game.ReplicatedStorage:FindFirstChild("Luck"))
normal = crystals.BasicCrystal:Clone()
shiny = crystals.ShinyCrystal:Clone()
dm = crystals.DarkMatterCrystal:Clone()
local chances = {
{name = "BasicCrystal", weight = 50},
{name = "ShinyCrystal", weight = 30},
{name = "DarkMatterCrystal", weight = 20},
}
local start = 0
local max = 25
function chooseCrystal()
local chosen = luck.SelectRarity(chances)
local newclone = crystals[chosen.name]:Clone()
newclone.Parent = game.Workspace.Plot
newclone.Prim.Position = Vector3.new(math.random(-11.75,50.25), math.random(5,5), math.random(-109.25, -41.75))
start += 1
end
game.ReplicatedStorage.Remotes.CrystalRemove.OnClientEvent:Connect(function()
if start <=0 then
return
end
start -= 1
print(start)
end)
while task.wait(1) do
if start == max then
return
end
chooseCrystal()
end