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

I want to get a book once AND ONLY ONCE??

Asked by 4 years ago

This is my script. https://pastebin.com/c3wZe7Dh

Nothing really happens it just doesn't work and no errors either. I'm new to scripting so i know this is probably the basic of the basic but I can't find out why it doesn't work, without the variables involved it works fine, but the thing is var DOES equal 2.

3 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

You need to move the ClickDetector connection to be outside the hit function, otherwise it will never get a chance to run. You also don't need the inner hit function. Something like this should work:

local var2 = 2

function hit(x)
    local y = x.Backpack
    local z = game.Workspace["TextBook"]

    if var2 == 2 then
        print(var2)
        z:Clone().Parent = y
        wait(3)
        var2 = 5
    end
end

script.Parent.ClickDetector.MouseClick:connect(hit)
Ad
Log in to vote
0
Answered by 4 years ago

It looks like you're creating two hit functions, so the first one is being overwritten. Be sure to use different (and preferably somewhat descriptive) variable and function names while programming. The reason why it's not doing anything, however, is because you've enclosed all the code inside the first hit function (be sure to indent please).

My suggestion would be to rewrite your code entirely because you forgot to put end to end statements, making it impossible for me to determine how your code was actually intended to be formatted. Also again, push that tab key.

Log in to vote
0
Answered by
Slatryte 104
4 years ago

There is some problems on the base I have noticed. You should say "local" before a variable name and you should NEVER add a number in a variable, it breaks the variable. You also named the functions the same thing, so the game doesn't know which one you mean.

local variable = 2
function hit(plr)
  local  y = plr.Backpack
  local  z = game.Workspace["TextBook"]
 end
function push(plr)
    if variable == 2 then
    print(variable)
    z:Clone().Parent = y
    wait(3)
    variable = 5
end

script.Parent.ClickDetector.MouseClick:connect(hit,push)

0
A variable name is fine having a number in it, as long as the number is not at the beginning. vector3_zero 1056 — 4y

Answer this question