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

Please Help me with this script?

Asked by
steev 0
10 years ago

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

Log in to vote
0
Answered by
Tesouro 407 Moderation Voter
10 years ago

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.

0
Maybe, you should insert a "if player then", to filter npcs and other stuff containing a Humanoid. Tesouro 407 — 10y
Ad

Answer this question