Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Button that spins/CFrames the wheel?

A while ago I created a clickable spinning wheel that uses CFrame to rotate it. But now it's become a problem due to excessive click spam. I could make the MaxActivationDistance 0, then wait a bit and go back to 32, but most of the time there are accidental spins. I want to use a button instead so that spam is prevented (Only I can spin the wheel). Here is the code for the actual wheel:

function onclicked()
game.Workspace.Spin:Play()
for i=1,20 do
		script.Parent.CFrame = script.Parent.CFrame * CFrame.Angles(0,-math.random(),0)
		wait(0.0001)
		script.Parent.CFrame = script.Parent.CFrame * CFrame.Angles(0,-.08,0)
		wait(0.0001)
		script.Parent.CFrame = script.Parent.CFrame * CFrame.Angles(0,-.08,0)
		wait(0.0001)
		script.Parent.CFrame = script.Parent.CFrame * CFrame.Angles(0,-.08,0)
end
for i=1,20 do
	
	    wait(0.001)
		script.Parent.CFrame = script.Parent.CFrame * CFrame.Angles(0,-.07,0)
		 wait(0.001)
		script.Parent.CFrame = script.Parent.CFrame * CFrame.Angles(0,-.07,0)
		 wait(0.001)
		script.Parent.CFrame = script.Parent.CFrame * CFrame.Angles(0,-.07,0)
end

		for i=1,15 do
			 wait(0.01)
		script.Parent.CFrame = script.Parent.CFrame * CFrame.Angles(0,-.04,0)
			 wait(0.01)
		script.Parent.CFrame = script.Parent.CFrame * CFrame.Angles(0,-.04,0)
		end
		
		for i=1,15 do
			
			 wait(0.001)
		script.Parent.CFrame = script.Parent.CFrame * CFrame.Angles(0,-.03,0)
			 wait(0.001)
		script.Parent.CFrame = script.Parent.CFrame * CFrame.Angles(0,-.03,0)
		end
		end
script.Parent.ClickDetector.MouseClick:connect(onclicked)

What I am trying to achieve is that when you click that spin button, the wheel will spin.

2 comments

0

Why have you got 2 lines the same for each for?

0

I'm not targeting that part, but I just want to make sure that the wheel does not stop at the same spot every spin. What I am saying is I need a button that CFrames the wheel itself instead of clicking the wheel.

1 answer

Why not use a debounce to prevent spam clicking?

http://wiki.roblox.com/index.php?title=Debounce

For example

local debounce = false
local variable = true

script.Parent.ClickDetector.MouseClick:connect(function()
	if debounce == false then
		debounce = true
	--Do not end your if statement here
		if variable == true then
			--do something
		else
			--do something
		end
	wait(1) -- wait 1 second before being clicked again
	debounce = false -- set debounce to false so the code can be run again
	end
end)

Hope this helps.

2 comments

0

I would but I'd rather have a button that spins the wheel, instead of clicking the actual wheel.

0

A gui button or a touch button?

This discussion is preserved as it was. New answers, comments, and votes are closed.