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

How to make clicking a part give a gear?

Asked by 6 years ago
Edited 6 years ago
Door = script.Parent
cooldown = 5 --How much time in seconds it takes for the door to open again. change if you wish.
value = false

function OnClicked()
    if (value == false) then
        value = true
    end
   local cloned = game.Lighting.Water:Clone()
    game.Lighting.Water:Clone().Parent = game.Players.LocalPlayer.Backpack


    Door.ClickDetector.MaxActivationDistance = 0
    wait(cooldown)

    value = false
    Door.ClickDetector.MaxActivationDistance = 10
end

script.Parent.ClickDetector.MouseClick:connect(OnClicked)

I try clicking on Door to get the 'Water' gear but it says LocalPlayer is a nil value. How can I tell it to give the gear to whoever is clicking?

It works in the studio, but not in the real game.

Door = script.Parent
cooldown = 5 --How much time in seconds it takes for the door to open again. change if you wish.
value = false

function OnClicked(player)
    if (value == false) then
        value = true
    end
   local cloned = game.Lighting.Water:Clone()
    game.Lighting.Water:Clone().Parent = player

    cloned.Handle.Anchored = false
    cloned.Handle.Locked = false

    Door.CanCollide = false
    Door.ClickDetector.MaxActivationDistance = 0
    wait(cooldown)

    value = false
    Door.ClickDetector.MaxActivationDistance = 10
end

script.Parent.ClickDetector.MouseClick:connect(OnClicked)
0
Add the argument ("player") at the start of your function it should work then. For example function OnClicked() would become function OnClicked(player) also change the clone parent to "player" The_sandwic 14 — 6y
0
Okay, I put up the revised script. This time it doesn't give me the tool on studio either. And output doesn't show me what's wrong. Edbotikx 99 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Door = script.Parent
cooldown = 5 --How much time in seconds it takes for the door to open again. change if you wish.
value = false

function OnClicked(player)
    if (value == false) then
        value = true
    end
   local cloned = game.Lighting.Water:Clone()
    game.Lighting.Water:Clone().Parent = player.Backpack -- Notice this

    cloned.Handle.Anchored = false
    cloned.Handle.Locked = false

    Door.CanCollide = false
    Door.ClickDetector.MaxActivationDistance = 0
    wait(cooldown)

    value = false
    Door.ClickDetector.MaxActivationDistance = 10
end

script.Parent.ClickDetector.MouseClick:connect(OnClicked)

You were parenting your tool to the player itself rather than the player's Backpack. Hopefully your script works now.

Best regards!

Ad

Answer this question