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

How to stop item giver from giving player item without a wait?

Asked by 4 years ago

So i found a script in where when a player touches a certain block, they get an item from the replicated storage. But when the player touches the block the block will keep on giving the player the item without a wait. What I want is the script to give the player the item but then to have a small wait (3 sec) so that when the player touches the brick it doesnt give the player like 5 swords, or 6 bow and arrows.

script.Parent.Touched:connect(onTouch)

function getPlayer(humanoid) 
local players = game.Players:children() 
for i = 1, #players do 
if players[i].Character.Humanoid == humanoid and players[i].Backpack:FindFirstChild("GhostBurger") == nil then return players[i] end
end 
return nil 
end 

function onTouch(part) 

local human = part.Parent:findFirstChild("Humanoid") 
if (human == nil) then return end 

local player = getPlayer(human) 

if (player == nil) then return end 

game.ReplicatedStorage:findFirstChild("Bow and Arrow"):clone().Parent = player.Backpack 

wait(10)

end 
script.Parent.Touched:connect(onTouch)

i need help a

0
if it worked, please accept the answer RobloxGameingStudios 145 — 4y

1 answer

Log in to vote
1
Answered by
IDKBlox 349 Moderation Voter
4 years ago

This isn't exactly what you're wanting but... if you put this within a script in a 'block'; This will allow players to get whatever item it is. Only if they don't already have it. So they can ONLY GET THE ITEM ONE TIME!

local part = script.Parent
local tool = game:GetService('ReplicatedStorage'):FindFirstChild('ITEMNAMEHERE')

if tool then
    part.Touched:Connect(function(hit)
        if hit and hit.Parent then
            local humanoid = hit.Parent:FindFirstChild('Humanoid')
            if humanoid then
                local player = game.Players:GetPlayerFromCharacter(humanoid.Parent)
                if player then
                    if not player.Backpack:FindFirstChild(tool.Name) and not humanoid.Parent:FindFirstChild(tool.Name) then
                        tool:Clone().Parent = humanoid.Parent
                    end
                end
            end
        end
    end)
end
0
It did solve my question a bit though. The reason why is that for some reason when the player gets the tool, after like 2 seconds the tool gets removed from their backpack. Can you fix that please? ImprinintInc 18 — 4y
Ad

Answer this question