I want to make a tool that only blacklisted players can use. When the tool is equipped, the player’s chatted message will go on a part. I’ve tried to do this before, but it didn’t go in the correct direction.
local players = game:GetService("Players")
local player = players.LocalPlayer or players.PlayerAdded:Wait()
local character = player.Character or player.CharacterAdded:Wait()
local backpack = player:WaitForChild("Backpack")
local part = workspace:WaitForChild("Part")
for i, v in pairs(backpack:GetChildren()) do
if v:IsA("Tool") and v.Name == "Tool" then --change tool name
v.Equipped:Connect(function()
player.Chatted:Connect(function(msg)
if part:FindFirstChildOfClass("SurfaceGui") then
part:FindFirstChildOfClass("SurfaceGui"):Destroy()
end
local surfaceGui = Instance.new("SurfaceGui")
surfaceGui.Parent = part
local label = Instance.new("TextLabel")
label.Parent = surfaceGui
label.Size = UDim2.new(1, 0, 1, 0)
label.FontSize = Enum.FontSize.Size96
label.Text = msg
end)
end)
end
end
Demonstration:
https://gyazo.com/2890789e70738909264a52686a927d78
Organisation:
Ok so I faced 2 issues, after the part is being equipped it will still chat on the part. Is there a backlisted list?
local players = game:GetService("Players")
local player = players.LocalPlayer or players.PlayerAdded:Wait()
local character = player.Character or player.CharacterAdded:Wait()
local backpack = player:WaitForChild("Backpack")
local part = workspace:WaitForChild("Part")
local equipped = false
for i, v in pairs(backpack:GetChildren()) do
if v:IsA("Tool") and v.Name == "Tool" then --change tool name
v.Equipped:Connect(function()
equipped = true
player.Chatted:Connect(function(msg)
if not equipped then
return
end
if part:FindFirstChildOfClass("SurfaceGui") then
part:FindFirstChildOfClass("SurfaceGui"):Destroy()
end
local surfaceGui = Instance.new("SurfaceGui")
surfaceGui.Parent = part
local label = Instance.new("TextLabel")
label.Parent = surfaceGui
label.Size = UDim2.new(1, 0, 1, 0)
label.FontSize = Enum.FontSize.Size96
label.Text = msg
end)
end)
v.Unequipped:Connect(function()
equipped = false
end)
end
end
The unequipped & still being able to chat was a simple fix. Should everyone have this tool (but only a few people can use it) or should only a few people have the tool?
Only a few people have the tool.
local storage = game:GetService("ServerStorage")
local tool = storage:WaitForChild("Tool") --change tool name
local players = game:GetService("Players")
local player = players.LocalPlayer or players.PlayerAdded:Wait()
local character = player.Character or player.CharacterAdded:Wait()
local backpack = player:WaitForChild("Backpack")
local part = workspace:WaitForChild("Part")
local equipped = false
local whitelisted = {"player1", "player2", "yournamehere"} --change names here
for i, name in pairs(whitelisted) do
if player.Name == name then
local clone = tool:Clone()
clone.Parent = backpack
end
end
for i, v in pairs(backpack:GetChildren()) do
if v:IsA("Tool") and v.Name == "Tool" then --change tool name
v.Equipped:Connect(function()
equipped = true
player.Chatted:Connect(function(msg)
if not equipped then
return
end
if part:FindFirstChildOfClass("SurfaceGui") then
part:FindFirstChildOfClass("SurfaceGui"):Destroy()
end
local surfaceGui = Instance.new("SurfaceGui")
surfaceGui.Parent = part
local label = Instance.new("TextLabel")
label.Parent = surfaceGui
label.Size = UDim2.new(1, 0, 1, 0)
label.FontSize = Enum.FontSize.Size96
label.Text = msg
end)
end)
v.Unequipped:Connect(function()
equipped = false
end)
end
end
Simply change the names inside the “whitelisted” table (you can have as many as you like).
New organisation:
Thank you so much! This really helped my game.
Also one more question, how do I change the background of the surfaceGui?
label.BackgroundColor3 = Color3.new(0, 0, 0)
Change 0 to a decimal between 0 and 1 for each.