Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Wheat Generator only generating a block?

Asked by
Time_URSS 146
4 years ago
Edited 4 years ago

Greetings,

I've made a script to generate a random wheat block from a list, but when you click multiple wheat blocks, it seems to choose always the same block. How can I fix that?

Main Script

local wheatGroup = workspace:WaitForChild("WheatFolder")
local genRandomWheat = game:GetService("ReplicatedStorage"):WaitForChild("GenRandomWheat")

local function generateRandom()
    local child = workspace.WheatFolder:GetChildren()
    print(#child)
    local x = 70/100*#child
    local y = math.floor(x)
    print(y)
    for i = 1,y do
        child[i].Transparency = 1
        child[i].CanCollide = false
        child[i]:WaitForChild("IsHarvested").Value = true
        child[i]:WaitForChild("ClickDetector").MaxActivationDistance = 0
    end
end

local function generateOneRandom()
    local child = workspace.WheatFolder:GetChildren()
    local x = #child/#child
    for i = 1,x do
        child[i].Transparency = 0
        child[i].CanCollide = true
        child[i]:WaitForChild("IsHarvested").Value = false
        child[i]:WaitForChild("ClickDetector").MaxActivationDistance = 10
    end
end

game.Players.PlayerAdded:Connect(generateRandom)
genRandomWheat.Event:Connect(generateOneRandom)

Every wheat script

local wheat = script.Parent.Parent
local clickDetector = wheat:WaitForChild("ClickDetector")
local isHarvested = wheat:WaitForChild("IsHarvested")
local genRandomWheat = game:GetService("ReplicatedStorage"):WaitForChild("GenRandomWheat")

local function harvest(player)
    if player then
        local playerRubbles = player.leaderstats:WaitForChild("Rubbles")
        if isHarvested.Value == false then
            playerRubbles.Value = playerRubbles.Value + 10
            isHarvested.Value = true
            wheat.Transparency = 1
            wheat.CanCollide = false
            clickDetector.MaxActivationDistance = 0
            genRandomWheat:Fire()
        else
            warn("Block is already harvested. Please harvest another time.")
        end
    else
        error("Player not detected. Please contact Time_URSS for this error. ERROR#051")
    end
end

clickDetector.MouseClick:Connect(harvest)

I can track the error over the line 20

0
It simply doesn't make sense making 2 else. Simply use elseif and then else, because computer would not understand if you put else and then else again. User#27525 1 — 4y

3 answers

Log in to vote
1
Answered by 4 years ago

You got to spawn in a block with a script when it grows back and then scale it and Material it to make it look like wheat or have it already made in Storage and clone it into workspace after grow.

Ad
Log in to vote
0
Answered by 4 years ago

at line 6 u need to remove a local

0
also i cant post a comment dark_nineret -25 — 4y
0
There's no problem with declaring a local function. ThatChristianGuy 27 — 4y
Log in to vote
0
Answered by
Time_URSS 146
4 years ago

Nvm, problem fixed. I had to change some things at lines 7 and 20, so now it's working perfectly. Thanks for your help!

Answer this question