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?
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.
Block.Touched:Connect(function(Hit)
if not game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent) then return end
Block.Size *= Block.Size.Magnitude
end)
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
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)
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.
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!