Hi,
I have a question regarding proximity prompt. I’m trying to have it where a player holds “e”, the part will start spinning around. For some reason, it doesn’t seem to work… I was wondering if I could get any help here. I have some idea of what may be the issue.
When I press “E” it doesn’t move at all, and I have little to no clue of what’s going on.
local partrotate = script.Parent
local stopspin = {}
while true do
partrotate.CFrame = partrotate.CFrame * CFrame.fromEulerAnglesXYZ(0,0,0)-- Change 6 to change speed
wait(0.01)
end
local startspin = {}
while true do
partrotate.CFrame = partrotate.CFrame * CFrame.fromEulerAnglesXYZ(0.6,0,0)-- Change 6 to change speed
wait(0.01)
end
prompt.Triggered:Connect(function()
if prompt.ActionText == "Start" then
startspin:Play()
prompt.ActionText = "Stop"
else
stopspin:Play()
prompt.ActionText = "Start"
end
end)
A “while do” loop can be stopped by adding a “Break” into the loop or it stop when the script is destroyed.
In this case, you can use a “repeat until” to do it.
Example script
local Prompt = script.Parent.ProximityPrompt
local Part = script.Parent
Prompt.Triggered:Connect(function()
if Prompt.ActionText == "Start" then
Prompt.ActionText = "Stop"
repeat
wait(0.01)
Part.CFrame = Part.CFrame * CFrame.fromEulerAnglesXYZ(0.6,0,0)
until
Prompt.ActionText == "Start"
elseif Prompt.ActionText == "Stop" then
Prompt.ActionText = "Start"
wait(0.025) -- Add +0.15s than the repeat time
Part.Orientation = Vector3.new(0,0,0)
end
end)
The reason why is probably because your not putting your loops in a coroutine and their isnt a Play function in one of your tables.
local partrotate = script.Parent
local spinning = false
local prompt = partrotate.ProximityPrompt
prompt.Triggered:Connect(function()
spinning = not spinning
prompt.ActionText = spinning and "Stop" or "Start"
end)
while wait(.01) do
if not spinning then
continue
end
partrotate.CFrame *= CFrame.fromEulerAnglesXYZ(.6,0,0)
end