Make glass NOT break when touched by a player

This script will “Shatter” the part when anything touches it, like glass does. What do I need to add it so it won’t break when touched by a player?

local broken = false
local shards = 9
local strength = 14

local sound = Instance.new("Sound",script.Parent)
sound.SoundId = "rbxassetid://2731462191"
sound.Volume = 2

script.Parent.Touched:Connect(function(part)
	if broken == false and part.Velocity.Magnitude > strength then
		broken = true
		sound:Play()
		print("Glass broken")
		local t = script.Parent.Transparency
		for i = 1,shards do
			local shard = Instance.new("Part")
			shard.Size = Vector3.new(
				script.Parent.Size.X/math.random(2,5),
				script.Parent.Size.Y/math.random(2,5),
				script.Parent.Size.Z/math.random(2,5)
			)
			shard.Position = script.Parent.Position - Vector3.new(
				math.random(-script.Parent.Size.X/2,script.Parent.Size.X/2),
				math.random(-script.Parent.Size.Y/2,script.Parent.Size.Y/2),
				math.random(-script.Parent.Size.Z/2,script.Parent.Size.Z/2)
			)
			shard.Orientation = Vector3.new(
				math.random(-360,360),
				math.random(-360,360),
				math.random(-360,360)
			)
			shard.Parent = script.Parent
			shard.Material = script.Parent.Material
			shard.Color = script.Parent.Color
			shard.Transparency = script.Parent.Transparency
			game.Debris:AddItem(shard)
		end
		script.Parent.Transparency = 1
		script.Parent.CanCollide = false
		script.Parent.destroy()
	end
end)

1 Like

Instead of velocity magnitude try velocity Y value

if part.Parent:FindFirstChild(“Humanoid”) then
return
else
glass breaks

if not part.Parent:FindFirstChild("Humanoid") then
-- rest of your script
end
2 Likes

oh yeah this is the one lol i forgot to actually reade it

1 Like

You could probably make the players strength something else

you misunderstand the script, the script said if you smash into it hard enough it shatters, not if the player is buff enough (that won’t make sense, then you need to add strength to every possible part)

1 Like

Just do this:

script.Parent.Touched:Connect(function(part)
	if not part.Parent:FindFirstChild("Humanoid") then
		-- rest of your script
	else return end
end)

Full script:

local broken = false
local shards = 9
local strength = 14

local sound = Instance.new("Sound",script.Parent)
sound.SoundId = "rbxassetid://2731462191"
sound.Volume = 2

script.Parent.Touched:Connect(function(part)
	if not part.Parent:FindFirstChild("Humanoid") then
		if broken == false and part.Velocity.Magnitude > strength then
			broken = true
			sound:Play()
			print("Glass broken")
			local t = script.Parent.Transparency
			for i = 1,shards do
				local shard = Instance.new("Part")
				shard.Size = Vector3.new(
					script.Parent.Size.X/math.random(2,5),
					script.Parent.Size.Y/math.random(2,5),
					script.Parent.Size.Z/math.random(2,5)
				)
				shard.Position = script.Parent.Position - Vector3.new(
					math.random(-script.Parent.Size.X/2,script.Parent.Size.X/2),
					math.random(-script.Parent.Size.Y/2,script.Parent.Size.Y/2),
					math.random(-script.Parent.Size.Z/2,script.Parent.Size.Z/2)
				)
				shard.Orientation = Vector3.new(
					math.random(-360,360),
					math.random(-360,360),
					math.random(-360,360)
				)
				shard.Parent = script.Parent
				shard.Material = script.Parent.Material
				shard.Color = script.Parent.Color
				shard.Transparency = script.Parent.Transparency
				game.Debris:AddItem(shard)
			end
			script.Parent.Transparency = 1
			script.Parent.CanCollide = false
			script.Parent.destroy()
		end
	else return end
end)

3 Likes

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