local sword = game.ReplicatedStorage.Sword -- Variable for the sword
script.Parent.TouchEnded:Connect(function(part)--When the block is touched, this function occurs. local is = false local player = game.Players:GetPlayerFromCharacter(part.Parent)--Variable for the player for i,v in pairs(player.Backpack:GetChildren()) do if v.Name == "Sword" then is = true end end
if is == false then if player then--If the thing that touched the object is the player then... sword:Clone().Parent = player.Backpack--Give the sword to the player end end
end)
Ok, so assuming that your issue is that it gives another sword when the person equips it, you also need to check if their Character has the "Sword" tool in it. When you equip a tool in Roblox, it moves from your backpack to your character.
local sword = game.ReplicatedStorage.Sword -- Variable for the sword local function checkForSword(par) -- this checks if a "Sword" exists in a model if par:FindFirstChild("Sword") then -- Checks if "Sword" exists return true end return false end script.Parent.TouchEnded:Connect(function(part)--When the block is touched, this function occurs. local player = game.Players:GetPlayerFromCharacter(part.Parent)--Variable for the player if player then if checkForSword(player.Backpack) then -- Checks backpack return -- Stops code end if player.Character and checkForSword(player.Character) then -- Checks Character return -- Stops code end end if player then--If the thing that touched the object is the player then... sword:Clone().Parent = player.Backpack--Give the sword to the player end end)