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

My ItemGiver script doesn't work. It doesn't print Yes4 and Yes5?

Asked by 4 years ago
--Local Script:
local player = game.Players.LocalPlayer
local Tool = script.Parent
local mouse = player:GetMouse()
local Character = player.CharacterAdded:Wait()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ItemGive = ReplicatedStorage:FindFirstChild("ItemGive")
local isEquipped = false

Tool.Equipped:Connect(function()
    isEquipped = true
end)

Tool.Unequipped:Connect(function()
    isEquipped = false
end)


mouse.Button2Down:Connect(function()

    print("Yes1") --Gets printed

    if isEquipped == true then

        print("Yes2") --Gets printed

        local MouseTarget = mouse.Target

        if MouseTarget ~= nil then

            print("Yes3") --Gets printed

            if MouseTarget.Parent:FindFirstChild("Humanoid") then

                print("Yes4") --Doesn't get printed

                local TargetPlayer = game.Players:GetPlayerFromCharacter(MouseTarget.Parent)

                if TargetPlayer ~= game.Players:GetPlayerFromCharacter(Character) then

                    print("Yes5") --Doesn't get printed

                    local TargetPlayerBackpack = TargetPlayer.Backpack

                    ItemGive:FireServer(TargetPlayerBackpack, Tool)

                    print("Success!") --Doesn't get printed

                end     

            end
            end
    end
end)


--ServerScript:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ItemGive = ReplicatedStorage:FindFirstChild("ItemGive")
local ToolToGetCloned = ReplicatedStorage:FindFirstChild("Tool")


ItemGive.OnServerEvent:Connect(function(plr, TargetPlayerBackpack)
    local ToolClone = ToolToGetCloned:Clone()
    ToolClone.Parent = TargetPlayerBackpack

end)
0
that means that you have to activate the tool at a character, I think marine5575 359 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

make

MouseTarget.Parent:FindFirstChild("Humanoid")

this

MouseTarget.Parent:FindFirstChildOfClass("Humanoid")or MouseTarget.Parent.Parent:FindFirstChildOfClass("Humanoid")

and have it print out the target

0
FindFirstChildWhichIsA has a recursive boolean. Shouldn't you stick with MouseTarget.Parent.Parent and that function? Fifkee 2017 — 4y
Ad

Answer this question