Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

click to unanchor?

Asked by 9 years ago

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

0
Keep in mind to supply the errors you may get. This will help people solve the issue better. Necrorave 560 — 9y
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. :) TheeDeathCaster 2368 — 9y

3 answers

Log in to vote
3
Answered by 9 years ago

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)
0
this somewhat worked thanks OfficialAndreJosh 10 — 9y
Ad
Log in to vote
3
Answered by
Tigerism 220 Moderation Voter
9 years ago
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)

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 OfficialAndreJosh 10 — 9y
Log in to vote
1
Answered by 9 years ago

Your problem:

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

0
i changed "if debounce = false then" into "if debounce == false then" and no change OfficialAndreJosh 10 — 9y

Answer this question