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

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

Asked by 3 years ago

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)

0
Can you post the code correctly so we can actually read it ezkatka1 50 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

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)
Ad

Answer this question