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

Humanoid Touch to Click Detector?

Asked by
Cactj -2
6 years ago

Hello,

After all of my desperate attempts to make this work, it hasn't been lol. I made a script for a key where if the humanoid touches the key, it is picked up. It will work better for my game if it is picked up if it is clicked. Any help? I will link the script below.

local key = script.Parent:WaitForChild('KeyUnion')
local weld = nil

key.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild('Humanoid') then
        if game.Players:GetPlayerFromCharacter(hit.Parent) then
            if game.Players:GetPlayerFromCharacter(hit.Parent).Team.Name == 'Safe' and key:IsDescendantOf(workspace) and key.Parent.Parent:FindFirstChild('Humanoid') == nil then               
                key.Parent.Parent = game.Players:GetPlayerFromCharacter(hit.Parent).Backpack
                print('hey')
            end
        end
    end
end)

script.Parent.Equipped:Connect(function()
    weld = Instance.new('Weld')
    weld.Part0 = script.Parent.Parent["Right Arm"]
    weld.Part1 = key
    weld.C0 = CFrame.new(0, -1, 0) * CFrame.Angles(-0.5 * math.pi, 0, 0)
    weld.C1 = script.Parent.Grip
    weld.Parent = script.Parent.Parent['Right Arm']
end)

script.Parent.Unequipped:Connect(function()
    if weld ~= nil then
        weld:Destroy()
        weld = nil
    end
end)

Thank you in advance.

0
Try using ClickDetectors if you want it to be clicked by something. It could be useful to be able to click and touch the key(because tapping on objects is really difficult on mobile) saSlol2436 716 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

If you use the Roblox Mouse https://wiki.roblox.com/index.php?title=API:Class/Mouse, you are able to access Mouse.Hit as well as Mouse.Target. What you would want to do is create a Local Script where you get the Mouse from the player, and then set up a MouseButton1Down (or Up for full click), and then when that fires you get the Mouse.Hit (or Target), and test to see if that is the key. If so, then you would fire a RemoteEvent across to the Server telling it that the Client has clicked on the key. The server can then destroy the key while the client records that the player has obtained it.

Ad

Answer this question