How is this script not working?

How is this script not working I have tried writing it in multiple different ways.
I have a tool named “Sword” in replicated storage and a folder created inside the player named “skin” with a intvalue inside named “skinequip”. I am trying to make it so that when it gives you the tool it changes the texture for you depending on the “skinequip” value. Here is the script. Any help appreciated

local RS = game:GetService("ReplicatedStorage")
local Tools = RS:FindFirstChild("Sword")

script.Parent.Touched:Connect(function(Hit)
    local Player = game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent)
    local Tool = Player.Backpack:FindFirstChild("Sword")  or Player.Character:FindFirstChild("Sword")
    if not Tool then
		local clone = Tools:Clone()
		clone.Handle.Mesh.TextureId.Value = Player.skin.skinequip.Value
		clone.Parent = Player.Backpack
    end
end)

Can we see the hierarchy of the player while you’re play testing?

AKA show us the children of the player in the Explorer when you’re play testing in studio

Here is a screenshot of all of the children

could it be because you dont have a condition for if the tool does exist?

I tried a different approach that seemed to work: instead of looking for the tool in replicated storage, I just made a script that I put in the tool that checks for when the tool is equipped. If the tool is equipped, change the texture of the mesh to skinequip.

local tool = script.Parent

tool.Equipped:Connect(function()
	local char = tool.Parent
	local player = game:GetService("Players"):GetPlayerFromCharacter(char)
	local skinEquip = player.skin.skinequip
	
	tool.Handle.Mesh.TextureId = skinEquip.Value
end)
1 Like

I tried the script but there is a problem, even when an id is in the value it still just puts no texture and makes the sword all grey when you equip it. But there are no errors with the sword

Oh I assumed the texture was supposed to be grey. That is probably a problem with the texture not matching up with the sword mesh rather than something with the code then.

You’re not even checking if there is a player

I figured it out, the value has to be a link instead of just the ID. Also the object that holds the value has to be a StringValue instead of an IntValue.
image
**Side note: don’t include the quotation marks when typing the link into the value

Here’s a pic of it working in studio:

Here’s the link that I used:
http://www.roblox.com/asset/?id=6406460929

Hope this helps.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.