Currently working on a new rp game. The thing is i’m trying to create a /give script but something is wrong. If there is anyone to help me please help.
game.Players.PlayerAdded:Connect(function(plr)
local p = plr.Data.FirstName.Value
local Character = workspace:FindFirstChild(p)
plr.CharacterAdded:connect(function(char)
plr.Chatted:connect(function(msg,Targ)
local Target = string.sub(msg, 7,30)
local first = string.sub(msg, 1,5)
if first == "/give" then
if workspace:FindFirstChild(Target) then
local Tool = char:FindFirstChildWhichIsA("Tool")
local GivePlayer = workspace:FindFirstChild(Target)
if Tool.Enabled then
Tool.Parent = game.Players:FindFirstChild(Target).Backpack
end
end
end
end)
end)
Sub returns a table of each letter so you would have to do split instead which returns the words
plr.Chatted:connect(function(msg,Targ)
local splitMsg= string.split(msg, " ")
local Target = splitMsg[3]
local givePlayer = game.Player:FindFirstChild(splitMsg[2])
local first = splitMsg[1]
if first and Target and givePlayer and first == "/give" then
local tool = WHEREEVER YOU KEEP YOUR TOOLS:FindFirstChild(Target)
if tool then
tool:Clone().Parent = givePlayer.Backpack
end
end
end)
game.Players.PlayerAdded:Connect(function(plr)
local p = plr.Data.FirstName.Value
local Character = workspace:FindFirstChild§
plr.CharacterAdded:Connect(function(char)
plr.Chatted:Connect(function(msg)
if msg:sub(1, 6) == "/give " then
local foundplayer = nil
local length = msg:len()
for i, v in pairs(game.Players:GetChildren()) do
if string.sub(msg:lower(), 7, length) == string.sub(v.Name, 1, legth-7) then
if char:FindFirstChildOfClass("Tool") then
char:FindFirstChildOfClass("Tool").Parent = v.Backpack
break
end
end
end
end
end)
end)
plr.Chatted:Connect(function(msg)
local splitMsg = string.split(msg, " ")
if splitMsg[1] = "/give" then
if game.Players:FindFirstChild(splitMsg[2]) then
local Tool = char:FindFirstChildWhichIsA("Tool")
if Tool then
Tool.Parent = game.Players[splitMsg[2].Backpack]
end
end
end)
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
local message = msg:split(" ")
if message[1]:lower() == "/give" then
if game.Players:FindFirstChild(message[2]:lower()) then
local tool = plr.Character:FindFirstChildWhichIsA("Tool")
if tool then
tool.Parent = game.Players:FindFirstChild(message[2]:lower()).Backpack
end
end
end
end)
end)