Hello! I been trying to script a Glass Broken and I was trying to make a Wedge Shape to make a glass break but I couldn’t script it, so I need some help. Here’s the script.
local glass = script.Parent
local originalGlass = glass:Clone()
local SoundId = "rbxassetid://12222005"
local PlaybackSpeed = 0.5
local function onGlassBroken(player)
print("Glass has been broken!")
print("Player: " .. player.Name .. " touched the glass.")
print("Glass is respawning in 5 seconds...")
warn("Glass has been broken by " .. player.Name)
end
local function respawnGlass()
wait(5)
local newGlass = originalGlass:Clone()
newGlass.Parent = game.Workspace
print("Glass has respawned!")
end
local function playBreakSound()
local sound = Instance.new("Sound")
sound.SoundId = SoundId
sound.Parent = game.Workspace
sound.PlaybackSpeed = PlaybackSpeed
sound:Play()
sound.Ended:Connect(function()
sound:Destroy()
end)
end
local function onTouch(player)
glass:Destroy()
onGlassBroken(player)
playBreakSound()
respawnGlass()
end
local function onTouched(hit)
local character = hit.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if player then
onTouch(player)
end
end
local function connectTouchedEvent()
glass.Touched:Connect(onTouched)
end
local function initGlass()
connectTouchedEvent()
end
local function main()
initGlass()
end
main()