*Noob question* Need help with event/function

This is probably such an obvious thing, I’m completely new to scripting/Lua and I’m to memorize everything I’ve learned so far with practice. Anyways, I have a problem with this:

function DoubleSize(part)
part.Size = part.Size * part.Size
end

Block.Touched:Connect(DoubleSize(Block))

I’m trying to make it where the part doubles in size when you (or well, anything, I’m not really there yet lol) touch it. But it immediately doubles in size when I run the game, without anything having touched it (it’s anchored in the air), can someone tell me why it’s doing that?

instead of

do

Block.Touched:Connect(DoubleSize)

only pass the function name in connect() https://developer.roblox.com/en-us/articles/events

1 Like

if you want to change part size you can do

part.Size = Vector3.new(number,number,number)

That’s what I did before changing it to Block.Touched:Connect(DoubleSize(Block)), but doing Block.Touched:Connect(DoubleSize) makes it double the size of the part it touches instead of the block itself, so when I touch it my body parts double in size instead of the block I touched.

When you do Touched:Connect(DoubleSize(part), the function is executed, use this

Block.Touched:Connect(function(Hit)
	Block.Size *= Block.Size.Magnitude
end)

also it is better to use Magnitude and

Detected by player
Block.Touched:Connect(function(Hit)
	if not game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent) then  return  end
	Block.Size *= Block.Size.Magnitude
end)

GetPlayerFromCharacter

Detected by a humanoid, player or NPC
Block.Touched:Connect(function(Hit)
	if not Hit.Parent:FindFirstChild("Humanoid") then  return  end
	Block.Size *= Block.Size.Magnitude
end)

if this is what you want, mark it as a solution.

1 Like
function DoubleSize(part)
part.Size = part.Size * part.Size
end

Block.Touched:Connect(function (hit)
DoubleSize(hit)
end)

just use my script im sure it will work fine

I don’t think there is a way to make it double in size using vector3 unless I use hard numbers, or is there? Like wouldn’t I have to type in vector3.new(4,2,4) if the size of the part was 2,1,2.
That’s why I just did part.Size + part.Size

you can multiply it part.Size = Vector3.new(CurrentPartSize) * 2

1 Like

Your script makes my body expand instead of the part itself.

then use this

function DoubleSize(part)
	part.Size = part.Size * 2
end
db = true
Block.Touched:Connect(function (hit) if db == true then db= false
		DoubleSize(hit)
		wait(3)
	end
		db=true
end)

if you dont want them to size so fast change wait time

This worked but it made the part really big immediately, but I changed it up a little and it now works how I wanted it to. Thanks! Also thanks I didn’t even know I could use Magnitude honestly, it was never mentioned in the videos I’ve been watching.

1 Like

you want the part you hit size change or the block ??

I wanted the block (that’s being touched) to change size.

iwas afk here imake it lil nice

g = {}

function DoubleSize(part)
	g.Size = part.Size * 2
	local n = TweenInfo.new(3)
	local sized = game.TweenService:Create(part,n,g)
	sized:Play()
end
db = true
script.Parent.Touched:Connect(function() if db == true then db= false
		DoubleSize(Block)
		wait(2)
		db=true
	end
end)

when you use touch events you will want to check to make sure that the object touching your part is a humanoid (ie a player). An example script for that would look like this

local part = script.Parent

local function onTouch(otherPart)
local humanoid = otherPart.Parent:FindFirstChild(‘Humanoid’)
if humanoid then
part.Transparency = 1

end

end

part.Touched:Connect(onTouch)

Inside the if then statement is where you would put your code that would want to run when the part is touched. Hope this clears up any confusion! :smiley: