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

guys, I'm sorry about this, but tell me how to make it so that the sword is given once?

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)

1 comment

0

Can you post the code correctly so we can actually read it

1 answer

✓ Accepted answer

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)

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