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

Please Help me with this script?

When the Player Touches a brick they get a LinkedSword. this is not working...

script.Parent.Touched:connect(function(player) -- Getting brick and defining the player.
end)

script.Parent.Touched:connect(function(player)
    local Tool = game.Workspace.LinkedSword:Clone(); -- Defining a tool that will be cloned.
    Tool.Parent = player.Backpack; -- Defining the parent of the cloned tool.
end)


1 answer

✓ Accepted answer

The touched event connects the part that touched it, not the player, what you can do is:

script.Parent.Touched:connect(function(part)
	if part.Parent:FindFirstChild("Humanoid") then -- checking if the part is a child of the character
		player = game.Players:GetPlayerFromCharacter (part.Parent) -- find the player
		Tool = game.Workspace.LinkedSword:Clone()
		Tool.Parent = player.Backpack
	end
end)

And there you go.

1 comment

0

Maybe, you should insert a "if player then", to filter npcs and other stuff containing a Humanoid.

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