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

How do I make this script detect the smooth terrain material?

local player = script.Parent.Parent
repeat wait() until player.Character


if player.Character:FindFirstChild('Sound') then
	player.Character.Sound:Destroy()
end
for i,object in pairs(player.Character.Head:getChildren()) do
	if object:IsA("Sound") then
		object:Destroy()
	end
end


local sound = {
	current = nil
}

sound.list = {
	fsConcrete = {"rbxasset://sounds/grassstone2.ogg",1.4,.4,true},
	fsCorrodedMetal = {"rbxasset://sounds/metalgrass.ogg",1.4,.3,true},
	fsDiamondPlate = {"rbxasset://sounds/metalgrass3.ogg",1.4,.3,true},
	  fsMetal = {"rbxasset://sounds/metalgrass3.ogg",1.4,.3,true},
	fsFoil = {"rbxasset://sounds/metal3.ogg",1.4,.3,true},
	fsGrass = {"http://www.roblox.com/asset/?id=16720281",1.8,.4,true},
	fsIce = {"rbxasset://sounds/icestone.ogg",1.4,.5,true},
	fsPlastic = {"http://www.roblox.com/asset/?id=121293429",1.8,.3,true},
	fsSlate = {"rbxasset://sounds/grassstone3.ogg",1.35,.4,true},
	fsGlacier = {"rbxasset://sounds/woodgrass3.ogg",1.35,.4,true},
	fsWood = {"rbxasset://sounds/woodgrass3.ogg",1.4,.5,true},
	  fsWoodPlanks = {"rbxasset://sounds/woodgrass3.ogg",1.4,.5,true},
	fsSmoothPlastic = {"http://www.roblox.com/asset/?id=121293429",1.8,.3,true},
	
	fsWater = {"http://www.roblox.com/asset/?id=130778103",1.6,.4,true},
	fsSnow = {"http://www.roblox.com/asset/?id=19326880",1.2,.5,true},
	
	jump = {"http://www.roblox.com/asset/?id=130778269",1,.3,false},


	fsAir = {'',1,0,false},
	
	fsBrick = {"rbxasset://sounds/grassstone3.ogg",1.4,.4,true},
	  fsCobblestone = {"rbxasset://sounds/grassstone3.ogg",1.4,.4,true},
	fsSand = {"http://www.roblox.com/asset/?id=131245944",1.4,.1,true},
	fsFabric = {"http://www.roblox.com/asset/?id=133705377",1.65,.5,true},
	fsGranite = {"rbxasset://sounds/grassstone3.ogg",1.35,.35,true},
	fsMarble = {"rbxasset://sounds/grassstone2.ogg",1.55,.38,true},
	fsPebble = {"http://www.roblox.com/asset/?id=133761546",1.5,.3,true},
}

math.randomseed(tick()) 

for name,data in pairs(sound.list) do
	local s = Instance.new("Sound",player.Character.Head)
	s.Name = name
	s.SoundId = data[1]
	s.Pitch = data[2]
	s.Volume = data[3]*.2 
	s.Looped = data[4]
	
	sound.list[name] = {s,data[2]}
end

local ground = {
	part = nil,
	position = nil
}


ground.detect = function()
	if player.Character:FindFirstChild('LowerTorso') then
		local ignore = {player.Character,workspace.CurrentCamera}
		local ray = Ray.new(player.Character.LowerTorso.Position,Vector3.new(0,-3.01,0))
		local hit,pos = workspace:FindPartOnRayWithIgnoreList(ray,ignore)
		ground.part = hit
		ground.position = pos
	end
end

local isWalking = false

player.Character.Humanoid.Running:connect(function(speed)
	if speed > 7 then
		isWalking = true
	else
		isWalking = false
	end
end)

player.Character.Humanoid.Jumping:connect(function(state)
	if not script:FindFirstChild('last_jumped') then
		
		local last_jumped = Instance.new('BoolValue',script)
		last_jumped.Name = 'last_jumped'
		game.Debris:AddItem(last_jumped,.5)
		
		ground.detect()
		if ground.part then
			if player.Character.Head:FindFirstChild('jump') then
				player.Character.Head.jump.Pitch= math.random((sound.list.jump[2]-.075)*100,(sound.list.jump[2]+.075)*100)/100
				sound.list.jump[1]:Play()
			end
		end
	end
end)

while wait(.35) do
	ground.detect()
	
	if isWalking and ground.part then
		
		local mat
		if ground.part.Name == "Water" or ground.part.Name == "Snow" or ground.part.Name == 'Air' or ground.part.Name == 'Glacier' then
			mat = ground.part.Name
		else
			mat = string.sub(tostring(ground.part.Material),15)
			mat = string.gsub(mat, "%s+", "")
		end
		
		if sound.current ~= sound.list["fs"..mat][1] then
			if sound.current then sound.current:Stop() end
			sound.current = sound.list["fs"..mat][1]
			sound.current:Play()
		end
		sound.current.Pitch= math.random((sound.list["fs"..mat][2]-.4)*100,(sound.list["fs"..mat][2]+.4)*100)/100
		sound.current.Pitch = sound.current.Pitch/(16/player.Character.Humanoid.WalkSpeed)
	elseif sound.current then
		sound.current:Stop()
		sound.current = nil
	end
end

6 comments

0

You new to scripting by any chance XD?

0

You are new but this guy isn't... I mean.. Look at this.. Recreating the entire walk sound effects?!

0

Why... just why..

0

You could try and take a look at this. http://wiki.roblox.com/index.php?title=Smooth_terrain#ReadVoxels Not sure if it is what you wanted.

0

What are you even trying to do

0

It's a copied script

1 answer

I’ll try to answer your question, but it’d be nice if you told us more clearly on what you wanted and attempted instead of throwing some complex script at us...

So there’s a property in the humanoid called FloorMaterial. It can detect both part material and terrain material. You can use this to know what kind of material the player is currently on.

Here’s an example :

local humanoid = script.Parent

humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
     print(humanoid.FloorMaterial)
end)

The function in this script prints every time the player steps on a different material. It’s that simple.

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