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

Tool giver script isn't cloning in the Workspace once a value has reached 100?

Asked by
nap516 87
7 years ago
Edited 7 years ago

The script is suppose to swap out the fake briefcase with the real brief case when a player touches the fake brief case but, it won't do it unless an intvalue is at 100.

Code for the briefcase swapper;

if script.Parent.Value.Value >= 99 then
while wait() do
    game.Workspace.BriefcaseClone.Handle.Touched:connect(function()
    wait(0.001)
        local clone = game.ReplicatedStorage.Briefcase:Clone()
    wait(0.001)
    game.Workspace.BriefcaseClone:Destroy()
    wait(0.001)
    clone.Parent = game.Workspace
end)
    end
        end

I have another code that adds 1 point to the IntValue once it gets clicked;

script.Parent.ClickDetector.MouseClick:connect(function(c)
    script.Parent.Value.Value = script.Parent.Value.Value + 1
end)

Help.

0
help nap516 87 — 7y

2 answers

Log in to vote
0
Answered by
OfcPedroo 396 Moderation Voter
7 years ago
Edited 7 years ago

You weren't clear, but if the IntValue has nothing to do with that, and if you only want the tools to swap, then, try this:

game.Workspace.BriefcaseClone.Handle.Touched:connect(function()
    game.Workspace.BriefcaseClone:Destroy()
    local clone = game.ReplicatedStorage.Briefcase:Clone()
    clone.Parent = game.Workspace
end)

But, if you actually want to that action be executed ONLY if that IntValue is 99 or bigger, then...

game.Workspace.BriefcaseClone.Handle.Touched:connect(function()
    if script.Parent.Value.Value > 98 then --I don't like using >= nor <= and that already failed some times to me, so, I'll just use > and less 1 value.
        game.Workspace.BriefcaseClone:Destroy()
        local clone = game.ReplicatedStorage.Briefcase:Clone()
        clone.Parent = game.Workspace
    end
end)

If this works for you, mark this answer as the solution, please. If this won't work, leave a comment telling why, and giving possible errors.

As always, good scripting! ;)

0
Worked thanks once again! I'll be sure to not use >= or<= anymore. nap516 87 — 7y
0
You can use it, but sometimes it failed to me, so I stopped trusting it. Just keep the good scripting! ;) OfcPedroo 396 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

Sometimes giving the clone a parent after you have cloned it is the right way to do it, try switching the destroy and parenting line out and seeing how it runs.

And also, the script.Parent.Value.Value line, is the script.Parent.[Value].Value the name for the actual int value?

Answer this question