- I’m stumped. I have figured out spawning randomly, but when I destroy a resource, it does not want to respawn. I have tried so many variations
I have looked all over the place for a solution and no such luck for what I want to accomplish.
I have simplified this code to not include random positions, etc. Any input thoughts, links, etc? I really need help understanding this concept. I have tried while true loops, etc. DM me if you are willing to assist over voice so I can understand this way better.
This block of code is in my server script service
replicatedStorage = game:GetService("ReplicatedStorage")
local StoneFolder = Instance.new("Folder")
StoneFolder.Name = "StoneFolder"
StoneFolder.Parent = workspace
local stoneIntValue = Instance.new("IntValue")
stoneIntValue.Name = "stoneIntValue"
stoneIntValue.Parent = StoneFolder
stoneIntValue.Value = 0
local minX = -15
local maxX = 5
local minZ = 0
local maxZ = 20
local stone = replicatedStorage.Ore.Stone
local numOfStones = 0
local function spawnStoneOre()
local clone = stone:Clone()
clone.Parent = workspace.StoneFolder
clone.Position = Vector3.new(0,0,0)
end
spawnStoneOre()
stoneIntValue.Changed:Connect(function()
print("IT WORKED")
end)
This block of code is for my pickaxe
local tool = script.Parent
local canMine = false
local Value = 0
local PickDamage = 10
local Type = "Pickaxe"
local destroyed = game.ReplicatedStorage.Ore.Stone.Destroyed
destroyed = false
local StoneIntValue = game.Workspace.StoneFolder.stoneIntValue
local function onTouch(otherPart)
script.Parent.Activated:Connect(function(Click)
if otherPart.Name == "Stone" and canMine then
canMine = false
otherPart.Health.Value = otherPart.Health.Value - PickDamage
game.Players.LocalPlayer.Stats.Stone.Value = game.Players.LocalPlayer.Stats.Stone.Value + 1
print("+1 Stone")
if destroyed == false and otherPart.Health.Value == "0" then
otherPart:Destroy()
StoneIntValue.Value = StoneIntValue.Value - 1
end
elseif otherPart.Name == "Iron" and canMine then
game.Players.LocalPlayer.PlayerGui.MiningError.Enabled = true
wait(4)
game.Players.LocalPlayer.PlayerGui.MiningError.Enabled = false
elseif otherPart.Name == "Copper" and canMine then
canMine = false
game.Players.LocalPlayer.PlayerGui.MiningError.Enabled = true
wait(4)
game.Players.LocalPlayer.PlayerGui.MiningError.Enabled = false
elseif otherPart.Name == "Gold" and canMine then
canMine = false
game.Players.LocalPlayer.PlayerGui.MiningError.Enabled = true
wait(4)
game.Players.LocalPlayer.PlayerGui.MiningError.Enabled = false
elseif otherPart.Name == "Diamond" and canMine then
canMine = false
game.Players.LocalPlayer.PlayerGui.MiningError.Enabled = true
wait(4)
game.Players.LocalPlayer.PlayerGui.MiningError.Enabled = false
end
end)
end
local function slash()
local str = Instance.new("StringValue")
str.Name = "toolanim"
str.Value = "Slash"
str.Parent = tool
canMine = true
end