Greetings, I want a tool when activated to make the player chat.
The issue is whenever I try it it is index nil.
I tried changing the code but it still doesn’t work, I haven’t found any solutions for the problem.
The error code it displays is: Workspace.Paper.Handle.Script:2: attempt to index nil with ‘Character’
Code:
script.Parent.Parent.Activated:Connect(function(A)
local Char = A.Character
local Chat = game:GetService("Chat")
Chat:Chat(Char.Head, "Secret documents???", 1)
end)
The argument “A” you have there will return nil, as there is no arguments that gets passed through when using the event “Activated”.
Therefore, you’re trying to get nil.Character, which is why you get an error. Instead, use this:
local Player = game:GetService("Players").LocalPlayer
script.Parent.Parent.Activated:Connect(function(A)
local Char = Player.Character or Player.CharacterAdded:Wait()
local Chat = game:GetService("Chat")
Chat:Chat(Char.Head, "Secret documents???", 1)
end)
From quickly brainstorming (not exactly testing), I could guess that it might be possible to make tools activated from a server script. However, this would take a whole other system and would be way too complicated.
Simply use a Local Script and do what I previously said.
local Player = game:GetService("Players").LocalPlayer
script.Parent.Parent.Activated:Connect(function(A)
local Char = Player.Character or Player.CharacterAdded:Wait()
local Chat = game:GetService("Chat")
Chat:Chat(Char.Head, "Secret documents???", 1)
end)
As far as I’m concerned, there is no reason at all to be equipping a tool from a Server Script.