How to enable CustomPhysicalProperties by script?

I am trying to enable CustomPhysicalProperties but it’s not working

I tried to do this:

CustomPhysicalProperties = true

but it didn’t work

You must use PhysicalProperties and one of its constructors.
https://developer.roblox.com/en-us/api-reference/property/BasePart/CustomPhysicalProperties

2 Likes

Do you mean something like this?:

local part = script.Parent

local density = .3
local friction = .1
local elasticity = 1
local frictionWeight = 1
local elasticityWeight = 1

local physProperties = PhysicalProperties.new(density, friction, elasticity, frictionWeight, elasticityWeight)
part.CustomPhysicalProperties = physProperties

I have tried this and it didn’t work

1 Like
local Part = script.Parent

local density = 0.3
local friction = 0.1
local elasticity = 1
local frictionWeight = 1
local elasticityWeight = 1
local physProperties = PhysicalProperties.new(density, friction, elasticity, frictionWeight, elasticityWeight)

Part.CustomPhysicalProperties = physProperties

Works fine for me. Make sure it’s a ServerScript with its Parent set to the Part you want to add CustomPhysicalProperties to. In other words, just make sure the location of the Script is under the Part you want to change.

1 Like

What I was trying to do is make every part that a player touch the CustomPhysicalProperties changes
And only want it to work for the client

Ah see you should have specified that earlier. You can check in a LocalScript if the player is touching a Part (and set its CustomPhysicalProperties) by doing the following:

local part = game.Workspace.Part --You could set whatever Part you want here

local function definePhysProperties(workspacePart)
	local density = 0.3
	local friction = 0.1
	local elasticity = 1
	local frictionWeight = 1
	local elasticityWeight = 1
	local physProperties = PhysicalProperties.new(density, friction, elasticity, frictionWeight, elasticityWeight)
	workspacePart.CustomPhysicalProperties = physProperties --Sets the properties to the given values from physProperties variable
end

local function onPartTouched(otherPart)
	if otherPart:IsA("BasePart") then
		local partParent = otherPart.Parent --Checks the parent of the BasePart touching your main part in the Workspace

		--Looks for a humanoid in this BasePart's parent
		local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
		if humanoid then
			definePhysProperties(part) --Set custom physical properties for the part you want changed
		end
	end
end

part.Touched:Connect(onPartTouched) --When Workspace part is touched, do... onPartTouched()

Hopefully this helped. Put it in StarterPlayerScripts (LocalScript, obviously) and make sure to change the “part” variable to whatever the Part’s name is you want changed located in the Workspace.

Didn’t work ):
I have changed the friction variable to something else to test it and it didn’t work ):