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

Clicking for a tool isn't working for some reason?

Asked by 4 years ago

So when the player clicks the item, they get a 'Bear' of which is in Replicated Storage, and it's then added to the player's startergear. When I click and reset, I've not been given the item. Am I missing some code? Did I mistype anything? I also need it so the player can only get the item once and it- (extra; disappears?) Please help me, I'm a little stuck ;-;

script.Parent.ClickDetector.MouseClick:connect(function(player)
        local plr = game.Players:findFirstChild(player.Name)
        game.ReplicatedStorage.Bear:Clone().Parent = player.StarterGear
        wait (3)
    end
0
(Also If for the extra (disappears part) I need it to only for the player. ToastyXoYT 5 — 4y
0
The Player parameter already refers to the Player Object of the Client that clicked... You must also use a Server-sided Script in workspace, as it is a globalized environment. Ziffixture 6913 — 4y

3 answers

Log in to vote
0
Answered by 4 years ago

Adding the tool to the player's startergear will make the player get the item every time they respawn. You should replace player.StarterGear with player.Backpack

    game.ReplicatedStorage.Bear:Clone().Parent = player.Backpack
0
I need it so it stays in their inventory ToastyXoYT 5 — 4y
0
add another line under it game.ReplicatedStorage.Bear:Clone().Parent = player.StarterGear bibi0629 82 — 4y
0
It didn't work? I'm confused sorry ToastyXoYT 5 — 4y
0
what do you mean by didn't work? doesn't stay or something else? (also if it didn't work you can just unaccept the answer) bibi0629 82 — 3y
Ad
Log in to vote
0
Answered by 4 years ago

For the gear, it would be Backpack and not StarterGear (if you wanted the gear to not be in the player's backpack every time the player respawn)

I would also change the find first child thing.

Although I haven't tested the script yet, I am certain that it works.

script.Parent.ClickDetector.MouseClick:connect(function(player)
        local plr = game.Players:GetPlayerFromCharacter(player.Parent)
        game.ReplicatedStorage.Bear:Clone().Parent = player.Backpack
        wait (3)
    end
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Ok so there are stuff to fix and also add, and i will also help you with getting the tool once so i really hope my scripts works and helps you.

local db = false

script.Parent.ClickDetector.MouseClick:Connect(function(player)
    if not db then
        db = true
            local plr = game.Players:GetPlayerFromCharacter(player.Parent)
        local bear = game.ReplicatedStorage.Bear
        bear:Clone().Parent = player.Backpack
        wait(9^9^9) --This will wait inf so the player wont get the tool again :)
        db = false
    end
end)

0
Sry about the indentation tho LetalNightmare 99 — 4y

Answer this question