Once a coin is picked up do you want it to spawn a random replacement or is there only 50 coins total?
Yeah, after a few seconds.
The maximum amount that is able to spawn at once is 50, but once one is picked up shortly another will spawn.
I guess that donāt matter ā¦ about the replacement
function gen()
local SS = game:GetService("ServerStorage")
local part = SS.coin:Clone()
part.Parent = workspace
local x = math.random(130,366)
local z = math.random(-156,162)
part.Position = Vector3.new(x,1.5,z)
end
for _= 1,50 do
gen() wait(5)
end
The 1.5 is where it looks right on my baseplate ā¦ youāll need to figure that out on yours.
This will put out 50 coins, slowly ā¦ in the code they pick up the coin add the gen function and call it once so it sets off a coin replacement. That will save you from constantly checking for coin numbers.
With many players picking up many coins a count number would be off at times. This way it will never be off.
Just tested, it worked. Thank you sooo much!
In the picked up a coin code with the gen function added you could do this ā¦
delay(5, function()
gen()
end)
That should keep everything rolling along with a delay on the new coin spawn. While being able to pick up more coins in the mean time.
Ok, that delay did work so great
But this will ā¦ (this script is inside the coin)
local rs = game:GetService("RunService")
local SS = game:GetService("ServerStorage")
local wait = function(t)
t=(t) or rs.Stepped:Wait();local n=tick();
repeat rs.Stepped:Wait()until(tick()-(n)>=(t))
end wait(2)
local paws = 0.06
local p = script.Parent
function gen()
print("test")
local part = SS.coin:Clone()
part.Parent = workspace
local x = math.random(130,366)
local z = math.random(-156,162)
part.Position = Vector3.new(x,1.5,z)
end
script.Parent.Touched:Connect(function(hit)
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
-- if player then player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1
-- delay(5, function()
gen()
-- end)
script.Parent:Destroy()
return
-- end
end)
while true do wait(paws)
p.CFrame = p.CFrame * CFrame.fromEulerAnglesXYZ(0.1, 0, 0)
end
Oh, did I just give away my epic real time wait function
Sorry for the late response. What is this part of the code for?
script.Parent.Touched:Connect(function(hit)
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
-- if player then player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1
-- delay(5, function()
gen()
-- end)
script.Parent:Destroy()
return
-- end
end)
while true do wait(paws)
p.CFrame = p.CFrame * CFrame.fromEulerAnglesXYZ(0.1, 0, 0)
end
Just asking because a lot of it was comments
That is where they pick it up ā¦ and it set off a new coin.
The rest is the coin spinning.
The rem is showing you where to add it to the leaderboard
The other was a test that failed ā¦
Ah, alright. So they will stay comments then?
oh nevermind lol
No, take that fail test out ā¦ and use the other if you do have a leaderboard or to add to wherever youāre keep track of coins collected. Youāll have to modify it to your leaderboard names.
I was trying to delay then right after deleted the script ā¦ drr
If you wanted that delay you could just wait with the coin none collision and transparent.
Wait the time then delete.
Okā¦just confirmingā¦ lol.
I put this in the coins script?
[quote=ātkuski08, post:33, topic:1851401, full:trueā]
Okā¦just confirmingā¦ lol.
I put this in the coins script?
[/quote
Yes, and you will even get a nice spinning coin. Take that spin out if you donāt like it.
Oh, so it needs the gen part to it, the coin itself already spins and gives the coin to the players leaderstat. Would i just add function(gen) (Cause it doesnt exist in the script)
In that case you would just add the gen() part
Easier to just have a coin add a new coin than keeping track of all the coins all the time.
And it would also be on count always, with no miscounts. win/win
delay(5, function()
gen()
end)
Sorry my peanut sized brain is so confused right now. The gen here is unknown global and doesnt exist. So above it I add the part clone thing?
forget that and just use gen()
Youāll have to add the Gen() function to that script too.
local SS = game:GetService("ServerStorage")
function gen()
print("test")
local part = SS.coin:Clone()
part.Parent = workspace
local x = math.random(130,366)
local z = math.random(-156,162)
part.Position = Vector3.new(x,1.5,z)
end
script.Parent.Touched:Connect(function(hit)
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if player then gen()
script.Parent:Destroy() -- if you got this covered remove this line
-- and just add this script to the coin, for a new gen() coin
end
end)
I would do this in the same script youāre working with removing the coin and adding it to the leaderboard. But you could use it as two scripts and it wouldnāt hurt anything.
Yeah, that was what I meant. Just tested it! Thank you again! Sorry for all of the confusion
I did end up putting it in a different script, just because I was scared of putting it in the wrong place.
Back up the script, do wild tests. If it blows up, go back to the backup and retry.
Programming 101.