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

When I click the part, the Sword should be in my inventitory?

Basically, if player touches the part "Purple" and if player has the ClassicSword, a print should appear "There is a sword"

local Detector = script.Parent.ClickDetector
local Tool = game.ServerStorage.ClassicSword
local Part = workspace.Purple
 
Detector.MouseClick:Connect(function(Player)
    local Clone = Tool:Clone()
    Clone.Parent = Player.Character
    Part:Destroy()
end)



workspace.Purple.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if hit.Parent.Backpack:FindFirstChild("ClassicSword") then
			print("There is a sword")
		end
	end
end)

1 answer

✓ Accepted answer

The Backpack is a child of the player, not inside their character. Try this:

local Detector = script.Parent.ClickDetector
local Tool = game.ServerStorage.ClassicSword
local Part = workspace.Purple

Detector.MouseClick:Connect(function(Player)
    local Clone = Tool:Clone()
    Clone.Parent = Player.Character
    Part:Destroy()
end)



workspace.Purple.Touched:Connect(function(hit)
    local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
    if hit.Parent:FindFirstChild("Humanoid") and player then
        if player.Backpack:FindFirstChild("ClassicSword") or hit.Parent:FindFirstChild("ClassicSword") then
            print("There is a sword")
        end
    end
end)

It gets the player from its character (hit.Parent.)

6 comments

0

It still doesn't work :/

0

Did you touch the Purple part first or click the button first?

0

I'm trying both ways

0

@EEnergy8 You're cloning the item to the character not the player's backpack

0

Cloning an item to the character automatically puts it in their backpack and equips it.

0

I edited it. Now see if it works.

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