Script gives error when putting player.Folder

Well, my mistake is that when playing a part with something, it should give money and perform other functions, but it gives an error when wanting to give money.

Vender - Roblox Studio 24_05_2021 10_34_29 p. m. (2)

local Give = script.Parent.Give
local Give2 = script.Parent.Give2
local Give3 = script.Parent.Give3

Give.Touched:Connect(function(hit, player)
	local char = hit.Parent
	if hit.Name == 'Tronco' then
		script.Parent.Anim.Value = 'false'
		script.Parent.Taken.Value = 'false'
		player:WaitForChild("FolderValues").Dinero.Value = player.FolderValues.Dinero.Value + 5
		game.Players:FindFirstChild(player.Name).PlayerGui.MenuDeMapa.Aviso:TweenPosition(UDim2.new(1.12, 0, 0.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.6, true)
		wait(0.37)
		game.Players:FindFirstChild(player.Name).PlayerGui.MenuDeMapa.Aviso.Visible = false
		game.Players:FindFirstChild(player.Name).PlayerGui.MenuDeMapa.Aviso.Tronco.Visible = false
		local ArmasTools = game.Players:FindFirstChild(player.Name).ArmasTools:GetChildren()
		local Backpack = game.Players:FindFirstChild(player.Name).Backpack

		for i, ArmasTool in pairs(ArmasTools) do
			ArmasTool.Parent = Backpack
		end
		hit:Destroy()
	end
end)
1 Like

The .Touched event doesn’t have a player parameter, so it returns nil since it doesn’t exist.

To get the player, do char.Parent. do GetPlayerFromCharacter like @lrisDev suggested.

3 Likes

char.Parent would just be workspace

to get player use

3 Likes

I don’t think they understand me … If the touch works, what gives an error is that when touching the touch, it should give an amount of money, but it does not do it and it gives an error.

i think your just getting the plr wrong

2 Likes

We already fixed the first error on line 10. Is there another error or is the line 10 error still occurring?

1 Like

I don’t think you understand us? It’s erroring because Player is never passed through the .touched function

So therefore doing Player:WaitForChild() will error because Player itself is nil

what you could do is

local Char = hit.Parent
local Player = game:GetService("Players"):GetPlayerFromCharacter(Char)