Roblox Forum banner

Roblox Studio - Why does this script not work

137 Views 1 Reply 2 Participants Last post by  Workindad01
I am trying to make a block of grass that will become shorter every time the player chops it with scissors I am new and still learning the code but I don't know why this wont work
anything will help

_G.TouchingFeild = false
local GrassRegrowTime = 1
local GrassregrowAmount = 10
local grass = 500
local GrassBlock = script.Parent
local scissors = game.StarterPack.Scissors



-- diffrent tools change the gras.value

--Sciccors
if _G.TouchingFeild == true and scissors.Activated then
grass.value -= 100
end

-- grass size
-- 0% missing
if grass.value <2000 and grass.value >900 then
GrassBlock.Size = Vector3.yAxis(1.65)

end

--10% missing
if grass.value <899 and grass.value >800 then
GrassBlock.Size = Vector3.yAxis(1.485)

end
--20% missing
if grass.value <799 and grass.value >700 then
GrassBlock.Size = Vector3.yAxis(1.32)

end

--30% missing
if grass.value <699 and grass.value >600 then
GrassBlock.Size = Vector3.yAxis(1.155)

end

--40% missing
if grass.value <599 and grass.value >500 then
GrassBlock.Size = Vector3.yAxis(0.99)

end

--50% missing
if grass.value <499 and grass.value >400 then
GrassBlock.Size = Vector3.yAxis(0.825)

end

--60% missing
if grass.value <399 and grass.value >300 then
GrassBlock.Size = Vector3.yAxis(0.66)

end
--70% missing
if grass.value <299 and grass.value >200 then
GrassBlock.Size = Vector3.yAxis(0.495)

end
--80% missing
if grass.value <199 and grass.value >100 then
GrassBlock.Size = Vector3.yAxis(0.33)

end
[/CODE]
See less See more
1 - 2 of 2 Posts
I just added a function to my standard touch script that I use. Make a grass part and put it into the touch part and play. It works but doesn't reset, too tired for that but you can use functions instead of if statements.

Code:
local player = game.Players
local touchPart = script.Parent
touchPart.CanCollide = false
local debounce = true

local function cutGrass(player)
    local grass = script.Parent.Grass -- tested with cylinder part
    grass.CFrame = grass.CFrame - Vector3.new(0, 0.25, 0)
    print("Cutting grass!")
    task.wait(1)
end

touchPart.Touched:Connect(function(otherPart)
    local character = otherPart.Parent
    local humanoid = character:FindFirstChild("Humanoid")

    if humanoid and debounce then
        debounce = false
        cutGrass()
        debounce = true
    end

end)

touchPart.TouchEnded:Connect(function(otherPart)
    local character = otherPart.Parent
    local humanoid = character:FindFirstChild("Humanoid")

    if humanoid and debounce then
        debounce = false
        print("Player left instance!")
        debounce = true
    end

end)
See less See more
1 - 2 of 2 Posts
Top