Part not changing size

script.Parent.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
local e = workspace.e.Size
e = Vector3.new(e.X + 2,e.Y,e.Z)
print(e)
else return
end
end)

The part X size isn’t changing.

Hey, this should work:

script.Parent.Touched:Connect(function(hit)
	
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	
	if plr then
		local e = workspace.e
		e.Size += Vector3.new(2, 0, 0)
	else 
		return
	end
	
end)

What it does it’s basically the same code, but then instead of adding 2 in the vector3 value, you just add a new vector3 value with the size of 2 on the X axis.

Screen Shot 2021-02-10 at 2.57.35 PM

The reason this doesn’t work is when using variables, if you call directly to the property of a part, aka Size in this case, it creates a cached version. Look here below:

local Part = Instance.new("Part", workspace) -- Create new part.
Part.Size = Vector3.new(1, 1, 1) -- Set size.
local PartSize = Part.Size -- Save it to a variable.
Part.Size = Vector3.new(10, 10, 10) -- Set size again.

print(PartSize) -- Outputs "1, 1, 1"
print(Part.Size) -- Outputs "10, 10, 10"

To fix this, all you need to do instead is:

script.Parent.Touched:Connect(function(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr then
        local e = workspace.e
        e.Size = Vector3.new(e.Size.X + 2,e.Size.Y,e.Size.Z)
        print(e.Size)
    else 
        return
    end
end)

Edit: whoops, forgot to do workspace.e on the setting size part

That’s true, but I think doing it like this is cleaner.

script.Parent.Touched:Connect(function(hit)
	
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	
	if plr then
		local e = workspace.e
		e.Size += Vector3.new(2, 0, 0)
	else 
		return
	end
	
end)
1 Like
local debounce = false

script.Parent.Touched:Connect(function(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr and not debounce then
        debounce = true
        local e = workspace.e
        e.Size = Vector3.new(e.Size.X + 2,0,0)
        print(e.Size X)
        wait(2)
        debounce = false
    end
end)
1 Like

Variables can’t store properties
local e = workspace.e.Size --from your script
The variable stored the value of that property

1 Like

Do realize that there is a cooldown of 2 seconds, not sure if that’s where Exabyte is going for.

Well if he step on the brick the event will be called multiple times making the size increase the couple times he stepped on it.