So uh, I suck at scripting and I don’t progress a lot cuz I tend to leave it time to time so I’m always stuck in the same knowledge level, but I’ve been trying to learn these days with phind AI but the AI is not very effective and makes scripts that just throw errors many times.
The problem is self-explanatory, basically a button that needs to be pushed forward changes direction when the parent object is rotated which is the button and the button is in a model which is basically a soda dispenser, so if I rotate the model obviously everything including the button is gonna rotate and the script works but it’s still following the same direction, and doesn’t change depending in parent object’s orientation, AND I HAVE NO IDEA HOW TO FIX THIS, so does anyone have a better solution than tweenservice or something? and yes I know the soda is in serverstorage instead of being inside the soda dispenser itself which is simpler for public uploads, but I chose that way.
script:
local ServerStorage = game:GetService(“ServerStorage”)
local TweenService = game:GetService(“TweenService”)
– Reference to the invisible part
local invisiblePart = script.Parent.Parent.spawn
– Reference to the soda in ServerStorage
local soda = ServerStorage:WaitForChild(“BloxyCola”)
– Debounce timer
local debounceTime = 0.5 – Adjust this value as needed
local lastClickTime = 0
– Function to spawn the soda
local function spawnSoda()
local newSoda = soda:Clone()
newSoda.Handle.Position = invisiblePart.Position
newSoda.Parent = workspace
-- Play sound effect
local buttonSound = script.Parent.Sound
if buttonSound then
buttonSound:Play()
end
end
– Function to toggle button state
local function toggleButtonState()
local button = script.Parent
-- Check if the button has a Size property
if typeof(button.Size) == "Vector3" then
local originalPosition = button.Position
-- Animate button push forward
local tweenInfo = TweenInfo.new(
0.3, -- Duration
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out
)
local tween = TweenService:Create(button, tweenInfo, {Position = Vector3.new(originalPosition.X + 0.1, originalPosition.Y, originalPosition.Z )})
tween:Play()
-- Wait for the animation to finish
tween.Completed:Connect(function()
-- Animate button back to original position
local revertTween = TweenService:Create(button, tweenInfo, {Position = originalPosition})
revertTween:Play()
spawnSoda() -- Spawn soda after animations complete
-- Change color of Signal part and PointLight
local signalPart = script.Parent.Parent.Signal
local pointLight = signalPart.PointLight
if signalPart then
local originalColor = signalPart.Color
-- Animate color change
local colorTween = TweenService:Create(signalPart, tweenInfo, {Color = Color3.new(0, 1, 0)})
colorTween:Play()
-- Wait for the animation to finish
colorTween.Completed:Connect(function()
-- Animate color back to original
local revertColorTween = TweenService:Create(signalPart, tweenInfo, {Color = originalColor})
revertColorTween:Play()
end)
end
if pointLight then
local originalColor = pointLight.Color
local originalBrightness = pointLight.Brightness
-- Animate color change
local colorTween = TweenService:Create(pointLight, tweenInfo, {Color = Color3.new(1, 1, 0)})
colorTween:Play()
-- Wait for the animation to finish
colorTween.Completed:Connect(function()
-- Animate color back to original
local revertColorTween = TweenService:Create(pointLight, tweenInfo, {Color = originalColor})
revertColorTween:Play()
-- Animate brightness change
local intTween = TweenService:Create(pointLight, tweenInfo, {Brightness = 2}) -- Increase brightness temporarily
intTween:Play()
-- Wait for the animation to finish
intTween.Completed:Connect(function()
-- Animate brightness back to original
local revertIntTween = TweenService:Create(pointLight, tweenInfo, {Brightness = originalBrightness})
revertIntTween:Play()
end)
end)
end
end)
end
end
– Find the ClickDetector on the button
local clickDetector = script.Parent:FindFirstChild(“ClickDetector”)
clickDetector.MouseClick:Connect(function()
local currentTime = tick()
if currentTime - lastClickTime > debounceTime then
lastClickTime = currentTime
toggleButtonState()
end
end)