Untitled
unknown
plain_text
a year ago
2.6 kB
5
Indexable
local part = script.Parent -- The part to step on
local targetPart = script.Parent.Parent.Target -- The part to modify (the target part)
local originalTransparency = targetPart.Transparency
local isTouching = false -- Track if the part is being touched
local fadeDuration = 0.3 -- Duration of the fade transition in seconds
local shrinkScale = 0.9 -- The scale factor for the button shrink effect
local soundId = "rbxassetid://0" -- Replace with the ID of the sound you want to play
local TweenService = game:GetService("TweenService")
local function isCharacterGrounded(character)
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
return humanoid.FloorMaterial ~= Enum.Material.Air
end
return false
end
-- Store the original size of the button
local originalSize = part.Size
local function updateTargetPartTransparency()
local transparency = 1
if isTouching then
transparency = 0
part.Material = Enum.Material.Neon
else
part.Material = Enum.Material.Plastic -- Change this to the original material of the button
end
TweenService:Create(targetPart, TweenInfo.new(fadeDuration), {
Transparency = transparency
}):Play()
end
local function updateButtonSize()
local scale = 1
if isTouching then
scale = shrinkScale
end
TweenService:Create(part, TweenInfo.new(fadeDuration), {
Size = originalSize * scale -- Use the original size as the base
}):Play()
end
local function onPartTouched(hit)
local character = hit.Parent
if character and character:IsA("Model") and character:FindFirstChild("Humanoid") then
if isCharacterGrounded(character) then
isTouching = true
updateTargetPartTransparency()
updateButtonSize()
targetPart.CanCollide = true
-- Play the sound
local sound = Instance.new("Sound")
sound.SoundId = soundId
sound.Parent = targetPart
sound:Play()
end
end
end
local function onPartTouchEnded(hit)
local character = hit.Parent
if character and character:IsA("Model") and character:FindFirstChild("Humanoid") then
if isCharacterGrounded(character) then
isTouching = false
updateTargetPartTransparency()
updateButtonSize()
targetPart.CanCollide = false
end
end
end
part.Touched:Connect(onPartTouched)
part.TouchEnded:Connect(onPartTouchEnded)
-- Reset button size when player leaves the area
part.AncestryChanged:Connect(function(_, parent)
if not parent then
-- Player has left the area, reset the button size
part.Size = originalSize
end
end)Editor is loading...
Leave a Comment