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

Why won't the puck bounce off the wall?

I'm trying to make a collision script where if a puck hits the wall, it goes the opposite direction. However, it's not even doing that. Here is the script:

local touched = true
local puck = workspace.Puck.BodyVelocity.Velocity
local X = puck.X
local Y = puck.Y
local Z = puck.Z

script.Parent.Touched:Connect(function(part)
	if touched then
		if part.Name == "Puck" then
			puck = Vector3.new(-X, Y, Z)
		end
	end
	
	touched = false
	wait(1)
	touched = true
end)

3 comments

0

Try playing with body forces

0

did you put a clickdetector

1 answer

You wrote down that puck was equal to the puck's velocity as a variable. This would set the variable's velocity to (-X, Y, Z), but not the puck's velocity. Try this:

local debounce = false
local puck = workspace.Puck.BodyVelocity
local X = puck.X
local Y = puck.Y
local Z = puck.Z

script.Parent.Touched:Connect(function(part)
	if part then
		debounce = false

	        if part.Name == "Puck" then
			puck.Velocity = Vector3.new(-X, Y, Z)
		end

		wait(1)
		debounce = true
	end
end)

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