Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

1 comment

0

Use Connect, not connect. Use FindFirstChild, not findFirstChild. Scripting is case sensitive, buddy.

1 answer

✓ Accepted answer

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.

2 comments

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

0

Sorry for the late reply, but no problem :D

This discussion is preserved as it was. New answers, comments, and votes are closed.