What do you want to achieve? Keep it simple and clear!
I wanna achive when player touch model he get’s tool
What is the issue? Include screenshots / videos if possible!
Issue is: nothing happening after i touch model.
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
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)
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
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
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