This scripts mimics a spell where you are able to see a character if you say the spell and their username but it doesn’t seem to work and I’m quite confused…
Local Script
local players = game.Players
local player = players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local ReplicatedS = game:GetService("ReplicatedStorage")
local PainEvent = ReplicatedS:WaitForChild("locate")
local Debounce = true
local mouse = player:GetMouse()
local connect
local UIS = game:GetService("UserInputService")
local canUseSpells = false
game.ReplicatedStorage.locatecam.OnClientEvent:Connect(function(player, target, item)
if target and item and player then
if canUseSpells == false then
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
game.Workspace.CurrentCamera.CFrame = game.Workspace.players:FindFirstChild(target.Name).Head.CFrame
wait(4)
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Fixed
canUseSpells = true
wait(2)
canUseSpells = false
else
warn("cannot use spells")
end
end
end)
player.Chatted:Connect(function(msg)
local str1 = string.split(msg,"faire a voir la re") -- spell
local str2 = string.split(msg,"") -- name
if str1 == string.lower("faire a voir la re") and game.Workspace:WaitForChild(str2).Name and Debounce == true and Character.Humanoid.Health > 0 then
Debounce = false
print("worked")
PainEvent:FireServer(str2)
wait(20)
Debounce = true
end
end)
ServerScript
local event = game.ReplicatedStorage.CharacterFiles.WitchEvents.locate
local event2 = game.ReplicatedStorage.CharacterFiles.WitchEvents.locatecam
local function Name(name)
for _, player in pairs(game.Workspace.players:GetChildren()) do
if player.Name:l() == name:lower() then
return player
end
end
end
event.OnServerEvent:Connect(function(Player, PlayerName, ItemName)
if ItemName then
local theItem = game.ReplicatedStorage.LocatorName:FindFirstChild(ItemName)
if theItem then
event2:FireClient(Player,theItem)
end
end
if PlayerName then
local str = Name(PlayerName)
if str then
event2:FireClient(Player,PlayerName)
end
end
end)
event.OnServerEvent:Connect(function(Player, PlayerName, ItemName)
local target = Name(PlayerName)
if target then
local TargetCharacter = game.Workspace:FindFirstChild(target.Name)
event2:FireClient(target)
elseif ItemName then
event2:FireClient(ItemName)
else
warn("Not found")
end
end)
Server Script
The player’s name is a string and it does not have a function called l, make this lower instead, like you did with the input name which is a string.
local event = game.ReplicatedStorage.CharacterFiles.WitchEvents.locate
local event2 = game.ReplicatedStorage.CharacterFiles.WitchEvents.locatecam
local function Name(name)
for _, player in pairs(game.Workspace.players:GetChildren()) do
if player.Name:lower() == name:lower() then
return player
end
end
end
event.OnServerEvent:Connect(function(Player, PlayerName, ItemName)
if ItemName then
local theItem = game.ReplicatedStorage.LocatorName:FindFirstChild(ItemName)
if theItem then
event2:FireClient(Player,theItem)
end
end
if PlayerName then
local str = Name(PlayerName)
if str then
event2:FireClient(Player,PlayerName)
end
end
end)
event.OnServerEvent:Connect(function(Player, PlayerName, ItemName)
local target = Name(PlayerName)
if target then
local TargetCharacter = game.Workspace:FindFirstChild(target.Name)
event2:FireClient(target)
elseif ItemName then
event2:FireClient(ItemName)
else
warn("Not found")
end
end)
If the player name is after the str1 part of the message, then I’m assuming there is another word after that which is the player name. Use str1[2] (which is the message after str1[1] = "faire a voir la re") instead of splitting "" from the message. If you wanted to split for every space in the message you’d use " ", not "".
LocalScript
local players = game.Players
local player = players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local ReplicatedS = game:GetService("ReplicatedStorage")
local PainEvent = ReplicatedS:WaitForChild("locate")
local Debounce = true
local mouse = player:GetMouse()
local connect
local UIS = game:GetService("UserInputService")
local canUseSpells = false
game.ReplicatedStorage.locatecam.OnClientEvent:Connect(function(player, target, item)
if target and item and player then
if canUseSpells == false then
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
game.Workspace.CurrentCamera.CFrame = game.Workspace.players:FindFirstChild(target.Name).Head.CFrame
wait(4)
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Fixed
canUseSpells = true
wait(2)
canUseSpells = false
else
warn("cannot use spells")
end
end
end)
player.Chatted:Connect(function(msg)
local str1 = string.split(msg,"faire a voir la re") -- spell
local str2 = string.split(msg,"") -- name
if str1 == string.lower("faire a voir la re") and game.Workspace:WaitForChild(str2).Name and Debounce == true and Character.Humanoid.Health > 0 then
Debounce = false
print("worked")
PainEvent:FireServer(str2)
wait(20)
Debounce = true
end
end)
Use FindFirstChild and you don’t need to check if it has a name. If you’re looking for a playing, look for them in the Players service, not workspace
LocalScript
local players = game.Players
local player = players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local ReplicatedS = game:GetService("ReplicatedStorage")
local PainEvent = ReplicatedS:WaitForChild("locate")
local Debounce = true
local mouse = player:GetMouse()
local connect
local UIS = game:GetService("UserInputService")
local canUseSpells = false
game.ReplicatedStorage.locatecam.OnClientEvent:Connect(function(player, target, item)
if target and item and player then
if canUseSpells == false then
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
game.Workspace.CurrentCamera.CFrame = game.Workspace.players:FindFirstChild(target.Name).Head.CFrame
wait(4)
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Fixed
canUseSpells = true
wait(2)
canUseSpells = false
else
warn("cannot use spells")
end
end
end)
player.Chatted:Connect(function(msg)
local str1 = string.split(msg,"faire a voir la re") -- spell
local str2 = str1[2] -- name
if str1[1] == string.lower("faire a voir la re") and game.Players:FindFirstChild(str2) and Debounce == true and Character.Humanoid.Health > 0 then
Debounce = false
print("worked")
PainEvent:FireServer(str2)
wait(20)
Debounce = true
end
end)