Hello, thanks for clicking on my thread. I have an issue with this code that I thought would work but doesn't. What happens is that when grabbing the tool, I thought adding break would stop the spinning but nothing worked. Instead of breaking the loop like it should. It continues to rotate and starts spinning the player when equipped. Please help!
The script is located inside of a handle and the handle is in a tool.
Code:
local handle = script.Parent handle.CanCollide = false handle.Touched:Connect(function() handle.Anchored = false end) while true do -- problem if handle.Touched == true then break else handle.CFrame = handle.CFrame * CFrame.fromEulerAnglesXYZ(0.1, 0.1, 0.1) wait() end end
This is an easy solution. The problem is that ".Touched" isn't a value, it's an event rather so to speak so it gets called on but isn't a true or false value. Instead you can set a variable to true calling something like "notTouched" and set at into the while loop just like the following:
handle = script.Parent notTouched = true --While loops only run as long as a value is true handle.CanCollide = false handle.Touched:Connect(function() handle.Anchored = false notTouched = false --Sets the value to false therefore making the while loop break end) while notTouched do --Keeps running as long as "notTouched" is true whateverCFrameValueYouHave = WhateverCFrameValueYouChange wait() end
If you have any questions or issues contact me. ;)
Instead of doing that you can do
while handle.Touched == false do -- you won't need a if statement
If way 1 doesn't works here is another way
while true do handle.Touched:Connect(function() break end) end
or you can just destroy the script because it looks like you have no other functions in there
local handle = script.Parent handle.CanCollide = false while wait() do handle.CFrame = handle.CFrame * CFrame.fromEulerAnglesXYZ(0.1, 0.1, 0.1) script.Parent.Touched:Connect(function() handle.Anchored = false script:Destroy() end) end