Cloning tool in player backpack

  1. What do you want to achieve? Keep it simple and clear!
    I wanna achive when player touch model he get’s tool

  2. What is the issue? Include screenshots / videos if possible!
    Issue is: nothing happening after i touch model.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tryed to get player.Character and his backpack. Yes, but didn’t find anything which could help me
    script:

local Player = game.Players:GetPlayerFromCharacter()
local tool = game.ServerStorage.Pepsi
local debugvalue = 0
if debugvalue == 0 then
workspace.StandartPepsi.Touched:Connect(function()
		debugvalue = debugvalue + 1
		local toolclone = tool:Clone()
		toolclone.Parent = Player.Backpack
end)
end

1 Like

You aren’t getting the player.
local Player = game.Players:GetPlayerFromCharacter() this line of code needs a model to be passed to get the player.
You should probably put it in the touched event.

workspace.StandartPepsi.Touched:Connect(function(part)
        local Player = game.Players:GetPlayerFromCharacter(part.Parent)
		debugvalue = debugvalue + 1
		local toolclone = tool:Clone()
		toolclone.Parent = Player.Backpack
end)
2 Likes

Ty lemme try that (30 letterssssssssss)

1 Like

Hmmm this is not working, still don’t get anyth

I added a check if a Player touched the part

local Player = game.Players.LocalPlayer
local tool = game.ServerStorage.Pepsi
local debugvalue = 0
if debugvalue == 0 then
workspace.StandartPepsi.Touched:Connect(function(Hit)
        if Hit.Parent:FindFirstChild("Humanoid") then
            debugvalue = debugvalue +1
            local toolclone = tool:Clone()
            toolclone.Parent = Player.Backpack
        else
            
        end
end)
end
1 Like

testing ( again 30 lettersssssss)

Copy the script again, i edited something that was wrong.

Don’t works, am i right if i using local script? or i need script?

I added a line copy the script again from my reply

Still no works, bruuuuuuuuuuuuuh

I used that script, amma try use script instead of local one

Theres a error on the output? eee

Yes when i made it to script it gave error

Tell me whats the error in the output

Workspace.StandartPepsi.Script:9: attempt to index nil with ‘Backpack’

local Player = game.Players.LocalPlayer
local tool = game.ServerStorage.Pepsi
local debugvalue = 0
if debugvalue == 0 then
workspace.StandartPepsi.Touched:Connect(function(Hit)
        if Hit.Parent:FindFirstChild("Humanoid") then
            debugvalue = debugvalue +1
            local toolclone = tool:Clone()
            toolclone.Parent = Player:WaitForChild("Backpack")
        else
            
        end
end)
end

image

My version of doing it:

local Players = game.Players:GetPlayerFromCharacter()
local tool = game.ServerStorage.Pepsi
local debugvalue = 0

if debugvalue == 0 then
	workspace.StandartPepsi.Touched:Connect(function(hit)
		if hit.Parent then
			local Player = Players[hit.Parent.Name]
			debugvalue = debugvalue + 1
			local toolclone = tool:Clone()
			toolclone.Parent = Player.Backpack
		end
	end)
end

Even don’t work, loool (30 letters)

This would never work, you are calling localplayer from the server.