Changing value of CustomPhysicalProperties

Hello and I am FestiveHarith, I am trying to achieve controlling and changing the values of roblox customphysicalproperties

(Here is the link from the roblox dev reference
BasePart.CustomPhysicalProperties)

I have tried to get it to work but the values will not change, I tried using variables and then try using int values (Its good to note that I am using roblox base water and NOT a custom part as water)

I have been searching the web but my idea hasn’t really been tried before, and my goal is actually to make custom buoyancy, so I have tried every trick in the book.

I have gone for 2 different ways of doing this.

  1. First using variables instead of Values.

image


local friction = 1
local elasticity = 1
local frictionWeight = 1
local elasticityWeight = 1
local density = script.DV1

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:wait()

local hrp = char:FindFirstChild("HumanoidRootPart")

local Userinputservice = game:GetService("UserInputService")
	

Userinputservice.InputBegan:Connect(function(Input, IsTyping)	
	if IsTyping then return end
	if Input.KeyCode == Enum.KeyCode("Q") then
		local physProperties = PhysicalProperties.new(density, friction, elasticity, frictionWeight, elasticityWeight)
		hrp.CustomPhysicalProperties = physProperties
	end


end)

2. With Values I have two different scripts, one in ServerScriptStorge (Seen below) and another that i have disabled


image


local densityVal = game.ReplicatedStorage.DV1

game.StarterGui.ScreenGui.Frame.Positive.MouseButton1Click:Connect(function()
	densityVal.Value = densityVal.Value + 0.1
		
		
end)

game.StarterGui.ScreenGui.Frame.Negitive.MouseButton1Click:Connect(function()
	densityVal.Value = densityVal.Value - 0.1
	
	

end)




image


local friction = 1
local elasticity = 1
local frictionWeight = 1
local elasticityWeight = 1
local densityVal = game.ReplicatedStorage.DV1

db = true

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:wait()

local hrp = char:FindFirstChild("HumanoidRootPart")


local Userinputservice = game:GetService("UserInputService")



local physProperties = PhysicalProperties.new(densityVal, friction, elasticity, frictionWeight, elasticityWeight)
hrp.CustomPhysicalProperties = physProperties





game.StarterGui.ScreenGui.Frame.Positive.MouseButton1Click:Connect(function()

		densityVal.Value = densityVal.Value + 0.1
		local physProperties = PhysicalProperties.new(densityVal, friction, elasticity, frictionWeight, elasticityWeight)
		hrp.CustomPhysicalProperties = physProperties
		wait(0.1)
		
end)

game.StarterGui.ScreenGui.Frame.Negitive.MouseButton1Click:Connect(function()
	
	densityVal.Value = densityVal.Value - 0.1
	local physProperties = PhysicalProperties.new(densityVal.Value, friction, elasticity, frictionWeight, elasticityWeight)
	hrp.CustomPhysicalProperties = physProperties
	wait(0.1)
	

end)



I hope you can help me!

Thanks Harith!

There are 2 issues I see with your script. 1. You are using StarterGui instead of PlayerGui, StarterGui sits on the server until a player joins the game. It is then cloned to the player. If I player is interacting with the GUI, you can get the GUI though
script.Parent
or
game.Players.LocalPlayer.PlayerGui.Ui

and 2. You changing the properties from the client. If you are changing anything in the workspace that need to impact every player, you need to fire a remote event to the server to change it.