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

Why doesn't this script deduct -0.1 size from the part?

Asked by 5 years ago

This is the script:

function onTouch(hit)
    mouse.Button1Down:Connect(function()
    if hit.Name == "Sand" then
        hit.Size = hit.Size -0.1
        end
    end)
end
script.Parent.Touched:Connect(onTouch)
0
I'd venture to guess it's because you are trying to subtract 0.1 from a Vector3. Try hit.Size = hit.Size - Vector3.new(-0.1, -0.1, -0.1) Optikk 499 — 5y
0
Also you might want to consider changing your code. I don't believe it will work how you expect it to. Optikk 499 — 5y

2 answers

Log in to vote
0
Answered by
Rheines 661 Moderation Voter
5 years ago

You cannot decrease a part's size property that way. You need to reduce its size by using a new Vector3. Also I'm not sure why you are defining Button1Down inside a Touched event, but I'm leaving it there anyways.

function onTouch(hit)
    mouse.Button1Down:Connect(function()
        if hit.Name == "Sand" then
            hit.Size = Vector3.new(hit.Size.X - 0.1, hit.Size.Y - 0.1, hit.Size.Z - 0.1)
        end
    end)
end)

script.Parent.Touched:Connect(onTouch)
Ad
Log in to vote
0
Answered by 5 years ago

Ok here is what you are doing wrong. First of all, I think you should make this script a bit.... easier to read. Unless you are going to use that function again you should probably format it differently.

script.Parent.Touched:Connect(function(hit)
end)

Instead of:

function OnTouch()
end
script.Parent.Touched:Connect(OnTouch)

Ok so now that that is over with, you need to change line 4 to this line:

hit.size = hit.size - Vector3.new(0.1, 0.1, 0.1)

If there is still a problem after you do this, it is most likely NOT the size.

0
dang it too lat RetroGalacticGamer 331 — 5y

Answer this question