How do I change the player character's friction?

Follow up from my old thread, I want to know how would I change the player’s character’s friction for future use.

I once set it up and it works fine but after I kept developing it, it somehow stopped working? I think i accidentally removed some part of it perhaps?

Here’s the script

local function setfriction(character)
	
	for _, part in pairs(character:GetChildren()) do
		if part:IsA("BasePart") then
			
			if not part.CustomPhysicalProperties then
				part.CustomPhysicalProperties = PhysicalProperties.new(part.Material)
			end
			
			local orig = part.CustomPhysicalProperties
			
			local density = 1
			local friction = GameBaseStats.BaseFriction
			local elasticity = 0.5
			local frictionWeight = 1
			local elasticityWeight = 1
			
			
			
			
			part.CustomPhysicalProperties = PhysicalProperties.new(density, friction, elasticity, frictionWeight, elasticityWeight)
		end
	end
end

(Yes I did call the function)

3 Likes

Did you add any other script in the player that might have disrupted the movement?

1 Like

I don’t think so? This is the only script that changes the friction of the character

1 Like

Since a players feet are CanCollide false are you sure you didn’t just change the Friction of the baseplate or Parts they are standing on?

I did not touch the parts they’re standing on at all

Bumping this.

Is it not working because it’s in a serverscript?

How did you try to call the script? Where is the script located?

it’s a server script, it calls when players joined and gets the character

It’s in server script storage

When you test the place do your character’s Parts Friction values = GameBaseStats.BaseFriction?

What is all this supposed to do:

			if not part.CustomPhysicalProperties then
				part.CustomPhysicalProperties = PhysicalProperties.new(part.Material)
			end
			
			local orig = part.CustomPhysicalProperties

If you look at the BasePart.CustomPhysicalProperties documention you’ll see you don’t need to set any of those.

How is GameBaseStats.BaseFriction set? Try putting in local friction = 0 instead. If the Friction sets to 0 then you know you have a problem with the variable.

GameBaseStats is a module where I modify overall values of something

I did call a require() when using it

Hey, I used this script and called it when a character is loaded, and it works as intended.

local function setfriction(character)
	
	local density = 1
	local friction = 0.2
	local elasticity = 0.5
	local frictionWeight = 1
	local elasticityWeight = 1

	for _, part in pairs(character:GetChildren()) do
		if part:IsA("BasePart") then

			if not part.CustomPhysicalProperties then
				print("not found for"..tostring(part))
				part.CustomPhysicalProperties = PhysicalProperties.new(density, friction, elasticity, frictionWeight, elasticityWeight)
			end

			--local orig = part.CustomPhysicalProperties

			--part.CustomPhysicalProperties = PhysicalProperties.new(density, friction, elasticity, frictionWeight, elasticityWeight)
		end
	end
end

game:GetService("Players").PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		setfriction(char)
	end)
end)

I even try setting the friction manually during playtest on server side and it doesn’t work???

1 Like

I tried it on a blank baseplate and it doesn’t work??? What’s going on with this engine.

1 Like

Where’d you place the script, and is it Local or Server?

I put mine as a server script. And, when you say doesn’t work, are you clicking the player’s model and checking for the custom physical properties?

Yup, I tried the script AND manual edit on server side.

It says that it has customphysicalproperties but it’s not slidy?

Ok… so i tried changing the density and it works now???

Still not the results that I want though.

(I want my players to starts off slow and ends with player slowly sliding (kind of like source game but with starting inertia) to prevent ADADADAD spamming)

So it wasn’t the matter of the script, it was the matter of number (idk why it worked tho cause when it was working i didn’t change the density)

Anyways, try change the density if friction isn’t working

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.