Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to change the size of only 1 surface of a part ?

I've added in my game a script. When we press the correct key it is supposed to create a beam in front of you that deals damage but there is a problem : I dont know how to change the size of only 1 surface of a part , without using Resize() caus it doesnt work with .Touched event. I tried using Vector3 but im not totally at ease with it. I found how to increase the size properly but the size does not increase in front. For example, if i chose to increase the Front size with Vector3, it also increase Back size. I though about modifying the position but i dont know how to do it.

So, i know that wasnt very simple to understand so, this is what is would like : When it grow (by the loop in the code down below) i would like the beam to always be at the correct position (the beginning just at my wand's position and the end at where i aimed the mouse)

Here is the code :

game:GetService("ReplicatedStorage").Tool.OnServerEvent:connect(function(player, position)
	-- the position variable is the position where the player clicked with the mouse
	local tool = game.Workspace[player.Name].WandTool
	
	local beam = script.Parent
	beam.CFrame = CFrame.new(tool.Emitter.CFrame.p, position)

	for i = 1,20 do
	beam.Size = beam.Size + Vector3.new(0,0,1) --This increase the size of both side (Front and Back, Top and Bottom, etc.... it depends of what side i chose to modify)
	beam.Position = beam.Position + Vector3.new(0,0,1) -- It doesnt do the right thing
	wait(0.1)
	end
end)

1 answer

✓ Accepted answer

Make a mental image of what happens. A direct resize changes two sides equally; each side extends by half the resize. To get the opposite side to its original position, you should use half the resize again, not the whole.

so this is probably all you need to change ye?

beam.Position = beam.Position + Vector3.new(0,0,0.5)

3 comments

0

When im using this method, the beam always go in the same direction, even if i move

0

Zurax, yes, but that's not the question you asked. You wanted to offset correctly. I fixed it.

0

I know, that's why i changed the question (not the whole question but just a little bit, to indicate what i realy want, because i know im often misunderstood))

This discussion is preserved as it was. New answers, comments, and votes are closed.