I’ve been trying to create a locator spell using string.split. You say the spell and if the character is in the game it moves your camera to the username you said but i’ve been having lot’s of trouble and confused myfself
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.CharacterFiles.WitchEvents:WaitForChild("locate")
local Debounce = true
local mouse = player:GetMouse()
local connect
local UIS = game:GetService("UserInputService")
local canUseSpells = false
ReplicatedS.CharacterFiles.WitchEvents.locatecam.OnClientEvent:Connect(function(player, target, item)
if target and player then
if canUseSpells == false then
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
game.Workspace.CurrentCamera.CFrame = game.Players:FindFirstChild(target.Name).Humanoid
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("found player")
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: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)
Visual example of what im trying to do: