#i need this object (coal) when touched to give the player the tool and also work with click

1 messages · Page 1 of 1 (latest)

spare kayak
#

ive been going at it for a while pls help

#

`local SS = game:GetService("ServerStorage")
local Tool = SS.GiveDrops:FindFirstChild("DropCoal")
local PlayerList = game:GetService("Players")

local Drop = script.Parent
local PickUp = Drop.ClickDetector

function giveTool(player)
local NewTool = Tool:Clone()
NewTool.Parent = player.Backpack
NewTool.Name = "Coal"

Drop:Destroy()

end

PickUp.MouseClick:Connect(function(player)
giveTool(player)
end)

Drop.Touched:Connect(function(player)
local DataPlayer = Players:GetPlayerFromCharacter(Drop.Parent)
print(DataPlayer)
if DataPlayer ~= nil then
print(88)
giveTool(DataPlayer)
end
end)
`

#

uhh idk how to format it like code on discord

#

uhh i forgot the problem is that idk how to makae it know its a player so it always errors adn says baseplate cant be given tools

topaz gazelle
#

it doesn't work? i checked your script and it seem normal with no error

lusty snowBOT
#

studio** You are now Level 1! **studio

spare kayak
#

it works in practise but it either dosent give the tool or errors and says baseplate dosent have a backpack

topaz gazelle
#

okay i find the error

spare kayak
#

thanks

topaz gazelle
#
Drop.Touched:Connect(function(hit)
    local DataPlayer = Players:GetPlayerFromCharacter(hit.Parent)
    if not DataPlayer then return end

    giveTool(DataPlayer)
end)
#

try this

#

juste remove the old touched function and replace with this one

spare kayak
#

hmm ok one sec

#

atempt to index nil with getplayer

topaz gazelle
#

do you have a variable Players? like

local Players = game:GetService("Players")
spare kayak
#

i save it as PlayerList

topaz gazelle
#

okay wait

#
Drop.Touched:Connect(function(hit)
    local DataPlayer = PlayerList:GetPlayerFromCharacter(hit.Parent)
    if not DataPlayer then return end

    giveTool(DataPlayer)
end)
#

now this one should work

spare kayak
#

hmm ok

#

yooooo it works

#

/tysm