hi!!! i am a sort of beginner with scripting. i know most of the basics and need help on something.
i am trying to make a viewport frame that shows a part. i want that part to spin when the players mouse is hovering over the gui. and also when the mouse leaves that gui then the part stays in the same position it is in. if anyone can help w this i would rlly appreciate!! thank uu <33
heres the script i am using. i do not know how to make it freeze when mouse leaves.
local spinning = false
local frame = script.Parent.Parent
local part = script.Parent
local partSpeed = 0.01
frame.MouseEnter:Connect(function()
if spinning then
part.CFrame = part.CFrame * CFrame.Angles(0,partSpeed,0)
end
end)
frame.MouseLeave:Connect(function()
local spinning = false
end)
Close, but the “if spinning” block should be inside its own while loop at the bottom of your code, outside of any events. The MouseEnter event itself should just be spinning = true
Also remove the local from MouseLeave. You want to reassign the existing variable, not create a new one.
local spinning = false
local frame = script.Parent.Parent
local part = script.Parent
local partSpeed = 0.01
frame.MouseEnter:Connect(function()
spinning = true
end)
frame.MouseLeave:Connect(function()
spinning = false
end)
while true do
if spinning then
part.CFrame = part.CFrame * CFrame.Angles(0,partSpeed,0)
end
end