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

Why does weapon not appear on actual game(appears on studio) when cloned to character?

Asked by 5 years ago
Edited 5 years ago

The weapon appears on studio but not on the game itself when it is cloned to the character

EDIT: Here is my equip script

player = game.Players.LocalPlayer
playerinWorkspace = player.Character.Name
inventory = script.Parent.Parent
inv_shown = false
local itemtoReplace

function replace()
    local item = script.Parent.theItem.Value
    print(itemtoReplace)
    if item then
        if item.itemEquipped.Value == true then
            print("This is already equipped")
        else
            if item.itemType.Value == "Weapon" then
                for j,k in pairs(player.Equip:GetChildren()) do
                    if k.itemType.Value == "Weapon" then
                        local itemName = k.Name
                        k:Destroy()
                    end
                end
                wait()
                print("lmao1")
                local itemtoEquip = item:Clone()
                itemtoEquip.Parent = player.Equip
                item.itemEquipped.Value = true
                itemtoReplace.itemEquipped.Value = false
                itemtoReplace = item
            end
        end
    end
end

function itemEquip()
    local item = script.Parent.theItem.Value
    if item then
            if item:findFirstChild("itemLevel") then
                if player.Stats.Lvl.Value < item.itemLevel.Value then
                    print("Put Errror Here")
                end
            end
            local found_wep = false
            if item:findFirstChild("itemType") then
                if item.itemType.Value == "Weapon" then
                    for j,k in pairs(player.Equip:GetChildren()) do
                        if k.itemType.Value == item.itemType.Value then
                            found_wep = true
                        end
                    end
                    for j,k in pairs(player.Character:GetChildren()) do
                        if k.ClassName == "Tool" then
                            if k.itemType.Value == item.itemType.Value then
                            found_wep = true
                            end
                        end
                    end
                if found_wep == false then
                        item.itemEquipped.Value = true
                        itemtoReplace = item
                        local clon = item:Clone()
                        clon.Parent = player.Equip
                        itemtoReplace = item
                        script.Parent.Visible = false
                else
                        print("Replace? Message")
                        replace()
                        script.Parent.Visible = false

                end
            end
    end
end

function Throw() 
    local item = script.Parent.theItem.Value
    if item:findFirstChild("itemType") then
        if item.itemType.Value == "Weapon" then
            for j,k in pairs(player.Equip:GetChildren()) do
                if k.itemType.Value == item.itemType.Value then
                    k:Destroy()
                    item:Destroy()
                    script.Parent.Visible = false
                end
            end
        end
    end
end

script.Parent.Equip.MouseButton1Click:connect(itemEquip)
script.Parent.Throw.MouseButton1Click:connect(Throw)

tried manually copying a working weapon into inventory and it works fine but using scripts to copy a weapon from the lighting to the inventory makes it broken

0
Use Connect, not connect. Use FindFirstChild, not findFirstChild. Scripting is case sensitive, buddy. User#19524 175 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Is this a LocalScript? If it is, and the game is Experimental Mode is off, then that's the problem. If you don't know what I mean, try searching on the internet. Tutorials on RemoteEvents and RemoteFunctions are everywhere.

0
Fixed it, the problem was the auto equip script putting it directly to the player from the equip configuration. I redirected it to backpack first before making the player its parent and its fixed :D. Thanks xxXTimeXxx 101 — 5y
0
Sorry for the late reply, but no problem :D Ultimate_Miner64 45 — 5y
Ad

Answer this question