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

click to unanchor?

i know this is a really stupid question and is probably pretty easy but i dont see why this script doesnt work

local debounce = false
function onclicked()
	if debounce = false then
		script.Parent.Anchored=false 
	end
end

clickDetector.MouseClick:connect(onMouseClick)

im using a local script btw

2 comments

0

Keep in mind to supply the errors you may get. This will help people solve the issue better.

0

Your problem is that you are using a 'LocalScript'; LocalScripts only replicate to the client, and do not work server-sided (unless put into the Players' Character). Please use a normal 'Script' instead, as that may solve your problem. :)

3 answers

✓ Accepted answer

Seeing as it's already answered, I'll just add example's and explain it the best I can.

Did you put your full code here, what is clickDetector referring to? If you posted your full code here, it should be either script.Parent or script.Parent.ClickDetector unless you made a variable referring to it.

Here's a example:

local clickDetector = Instance.new("ClickDetector",script.Parent)

Like TheDeadlyPanther said, if you use the if statement, you have to use == not =. And like TheAlphaStigma said, LocalScript's only replicate to the client, and do not work server-sided (unless put into the Players' Character).

You could also replace if debounce == false then to if not debounce then

Example:

local debounce = false

if not debounce then
	print("I like cows.")
end

You can replace the function onclicked() and clickDetector.MouseClick:connect(onMouseClick) to clickDetector.MouseClick:connect(function() print("I like cows") end) to make it some-what shorter.

Example:

local clickDetector = Instance.new("ClickDetector",script.Parent)

clickDetector.MouseClick:connect(function()
	print("I like cows")
end)

Final script:

local clickDetector = Instance.new("ClickDetector",script.Parent)

clickDetector.MouseClick:connect(function()
	script.Parent.Part.Anchored = false
end)

If you want it to unanchor everything in a model.

local clickDetector = Instance.new("ClickDetector",script.Parent)

clickDetector.MouseClick:connect(function()
	for _,v in pairs(game.Workspace.Model:GetChildren()) do
		if v:IsA("BasePart") then
			v.Anchored = false
		end
	end
end)

1 comment

0

this somewhat worked thanks

local debounce = false
clickDetector.MouseClick:connect(function()
	if debounce then return end
	debounce = true
	script.Parent.Anchored=false
	--optional,  add a wait() to make debounce = false
end)

1 comment

0

i reput in that code in the script with how you wrote it but still doesnt work in studio and in playing the game without

Your problem:

When seeing if something is equal to another, you use == instead of =.

1 comment

0

i changed "if debounce = false then" into "if debounce == false then" and no change

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