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

Why is the tool not cloning into players backpack?

Asked by 4 years ago

Ok so I have a localscript in a textbutton that checks if a boolvalue thats in the player is true or not, and then if its true it clones a specified tool into the players backpack but it doesn't clone. Heres the script:

script.Parent.MouseButton1Down:Connect(function()
    local player = game.Players.LocalPlayer
    local Sharingan = game.ReplicatedStorage.KG:FindFirstChild("Itachi Mangekyou"):Clone()
    local SharValue = player.KGvalues:FindFirstChild("Sharingan")

    SharValue.Changed:Connect(function()
        if SharValue.Value == true then
            Sharingan.Parent = player.Backpack
        end
    end)
end)

1 answer

Log in to vote
0
Answered by 4 years ago

Here are a few suggestions first:

I would recommend using the Activated event instead of MouseButton1Down. Also, we really only use the FindFirstChild() function to check whether the object exists. If you're sure the object exists, there's really no point in using it.

Here's what I think the problem that's breaking your script is:

You're firing this from a local script, but you're using it to directly clone something into the player. Because of FilteringEnabled, this will not work.

I would suggest firing a RemoteEvent or RemoteFunction using FireServer() or InvokeServer(). So, I would put a remote event into Replicated Storage and replace line 8 with something along the lines of this:

game.ReplicatedStorage.RemoteEvent:FireServer(player)

Then, I'd create an event in a server script like this:

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(plr)
    local Sharingan = game.ReplicatedStorage.KG:FindFirstChild("Itachi Mangekyou"):Clone()
    Sharingan.Parent = plr.Backpack
end)
0
Ok thanks Sabertooth11123 38 — 4y
0
It didn't work :( Sabertooth11123 38 — 4y
Ad

Answer this question