I’m trying to make this mechanic in my game at a certain point where collectibles will spawn in a plot area, rarer ones giving more currency once collected. So far I’ve got the spawning and the RNG factor working smoothly so that’s good.
The problem being; whenever I walk over them to collect them, usually I’m only ever able to collect three specific ones for whatever reason. They are supposed to increase your currency count, decrease the ‘soulAm’ value in the plot itself (This will be explained later on in the post) so it’s no longer at the ‘cap’ value and then disappear, only three specific ones do that.
At first I figured I needed to disable the script inside the soul itself to see if that was the issue, but that provided the exact same results. Afterwards I tried moving the big ‘spawnField’ brick into the ground using scripting and had the souls spawn five studs above it since I figured maybe them making contact with the brick itself was somehow causing problems, but to no avail. I even tried moving the line of code that destroys the soul itself to see if that changed anything; it did, it did disappear but it didn’t add anything to my currency count or decreased the ‘soulAm’ value.
debounce = false
worth = workspace.sfr1Val.Value -- How much the soul is worth, I use values in the workspace just in case I need to change their worth for any reason without having to manually go through ALL of them.
script.Parent.Touched:connect(function(hit, Player)
if debounce == false then
debounce = true
local check = hit.Parent:FindFirstChild("Humanoid")
if check ~= nil then
local user = game.Players:GetPlayerFromCharacter(hit.Parent)
local stats = user:findFirstChild("leaderstats")
if stats ~= nil then
local exp = stats:findFirstChild("EXP")
exp.Value = exp.Value + worth
script.Parent.Parent.soulAm.Value -= 1 -- Decreases the amount of souls present in the plot so more can spawn if it's already at the 'cap' value.
script.Parent:Destroy()
end
end
end
end)
Here is the script for one of the souls, the rest of them are pretty much the same with only the workspace value being different for each one.
cd = 2 -- Soul spawn cooldown
x = 0 -- RNG number
script.Parent.spawnField.Position -= Vector3.new(0,5,0) -- The thing I had mentioned earlier in the post
while true do
task.wait(cd)
if script.Parent.soulAm.Value ~= script.Parent.cap.Value then -- If the amount of souls isn't at the capped value, then they will continue to spawn
x=math.random(1,200) - I did 1 through 200 to simulate the decimals seen on the sign in the first screenshot
if x <= 130 then -- Magenta soul
script.Parent.soulAm.Value += 1 -- Soul takes up space in the plot
soul = game.ReplicatedStorage.SFRuinsSouls.sfrSoul1:Clone()
soul.Parent = script.Parent
xpos = math.random(-(script.Parent.spawnField.Size.X),script.Parent.spawnField.Size.X)
zpos = math.random(-(script.Parent.spawnField.Size.Z),script.Parent.spawnField.Size.Z)
soul.Position = Vector3.new(script.Parent.spawnField.Position.X+(xpos/2),script.Parent.spawnField.Position.Y+5,script.Parent.spawnField.Position.Z+(zpos/2)) -- Randomizes the soul's position on the plot board
elseif x >= 131 and x <= 180 then -- Purple soul
script.Parent.soulAm.Value += 1
soul = game.ReplicatedStorage.SFRuinsSouls.sfrSoul2:Clone()
soul.Parent = script.Parent
xpos = math.random(-(script.Parent.spawnField.Size.X),script.Parent.spawnField.Size.X)
zpos = math.random(-(script.Parent.spawnField.Size.Z),script.Parent.spawnField.Size.Z)
soul.Position = Vector3.new(script.Parent.spawnField.Position.X+(xpos/2),script.Parent.spawnField.Position.Y+5,script.Parent.spawnField.Position.Z+(zpos/2))
elseif x >= 181 and x <= 199 then -- Dark Indigo soul
script.Parent.soulAm.Value += 1
soul = game.ReplicatedStorage.SFRuinsSouls.sfrSoul3:Clone()
soul.Parent = script.Parent
xpos = math.random(-(script.Parent.spawnField.Size.X),script.Parent.spawnField.Size.X)
zpos = math.random(-(script.Parent.spawnField.Size.Z),script.Parent.spawnField.Size.Z)
soul.Position = Vector3.new(script.Parent.spawnField.Position.X+(xpos/2),script.Parent.spawnField.Position.Y+5,script.Parent.spawnField.Position.Z+(zpos/2))
elseif x == 200 then -- Dark Blue soul
script.Parent.soulAm.Value += 1
soul = game.ReplicatedStorage.SFRuinsSouls.sfrSoul4:Clone()
soul.Parent = script.Parent
xpos = math.random(-(script.Parent.spawnField.Size.X),script.Parent.spawnField.Size.X)
zpos = math.random(-(script.Parent.spawnField.Size.Z),script.Parent.spawnField.Size.Z)
soul.Position = Vector3.new(script.Parent.spawnField.Position.X+(xpos/2),script.Parent.spawnField.Position.Y+5,script.Parent.spawnField.Position.Z+(zpos/2))
end
end
end
And here’s the script for the plot spawning the souls, in case that has anything to do with why the souls won’t work.
If anybody could provide an answer to this strange scripting mystery then that would be greatly appreciated, thank you! ^ ^