Script wont work

CD.Triggered:Connect(function(Player)
	local tool = character:FindFirstChildOfClass("Tool")
	if tool == nil then end
	if tool.Name ~= nil then
		local Name = tool.Name
print(Name)

When proximity prompt is triggered this dont character:FindFirstChildOfClass("Tool")

What is character? Try access the character through Player

2 Likes

yes, i did it

local player = players.LocalPlayer
local character = player.Character

No need to define player twice in this case. You could use the Player parameter to get the character. It happens possibly because you have 'Player(localplayer)andPlayer(parameter)`

I can say that tool’s name never can be nil. If it’s empty,it will be “”

i changed, but its still dont working

local localplayer = game:GetService("Players").LocalPlayer
local character = localplayer.Character
local Humanoid =character:FindFirstChild('Humanoid')

local or server script?

its local script
also , there is full script

local ss = game:GetService("ServerStorage")
local rs = game:GetService("ReplicatedStorage")

local localplayer = game:GetService("Players").LocalPlayer
local character = localplayer.Character
local Humanoid =character:FindFirstChild('Humanoid')

local Dirt = script.Parent.Parent.Parent
local CD = script.Parent
local chest = script.Parent.Parent.Parent.Chest
local Click = script.Parent.Parent
local data = rs.FetchClientData:InvokeServer()

local counter = 0 

local db = false

local Z = chest.Position.Z
local X =  chest.Position.X
local Y = chest.Position.Y 
CD.Triggered:Connect(function(Player)
	print("t")
	local tool = character:FindFirstChildOfClass("Tool")
	if tool == "" then end
	if tool.Name ~= nil then
		local Name = tool.Name
		if db == false then
			db = true
			local Y = chest.Position.Y + 1
			chest.Position = Vector3.new(X,Y,Z)
			counter += data[Name].Damage
			else
				if counter > 6 then 
					Click:Destroy()
			end
			wait(0.1) db = false
		end
	end
end)

What doesn’t work to be exact?

the whole function, its dont printing anything too

character is nil because the game hasn’t loaded yet
try local character = localplayer.Character or localplayer.CharacterAdded:Wait()

changed, but the function dont running

show me the output, it would definitely be appreciated

Where is the script/local script located?

notinh in output, he dont printing anything so the function dont run

image in server storage, when the game starting this chest spawning in random position

The problem is proximities don’t work with local scripts so that’s why. Only server scripts*

tool must be equipped in order for the function to work, are you aware?

The problem is as I said that proximity prompt’s don’t work with local scripts only server scripts. So he’ll have to fire and event from the server to the client.

1 Like