What do you want to achieve?
I’m trying to make a “!view [Target]” where it makes you spectate the target.
What is the issue?
It isn’t working!
Here is my code for module script:
function Commands.view(player, args)
local starter = player
player = nil
local plrs = game.Players:GetPlayers()
for _,v in pairs(plrs) do
if string.match(v.Name:lower(), args[2]) then
player = v
break
end
end
if not player then
warn(args[2] .. ' does not exist.')
end
local char = player.Character
if not char then return end
local re = player.Character.CameraManipulation.RemoteEvent
re:FireClient(player, player.Character)
end
What solutions have you tried so far?
I’ve done anything I could think of. I tried using remote events in any way possible I could think of but nothing worked.
My script that gets the module:
local commands = require(script.Commands)
local prefix = "!"
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
msg = string.lower(msg)
local split = string.split(msg,' ')
local cmd = split[1]
if cmd:sub(1,1) ~= prefix then return end
if commands[cmd:sub(2,#cmd)] then
commands[cmd:sub(2, #cmd)](player,split)
end
end)
end)
function Commands.view(**player**, args)
local starter = player
player = nil
local plrs = game.Players:GetPlayers()
for _,v in pairs(plrs) do
if string.match(v.Name:lower(), args[2]) then
**player** = v
break
end
end
if not player then
warn(args[2] .. ' does not exist.')
end
local char = player.Character
if not char then return end
local re = player.Character.CameraManipulation.RemoteEvent
re:FireClient(player, player.Character)
end
Your issue is that the script is working as expected, but you are firing the remote event wrong. Player is already defined when you call Commands.view, but then you change that value when you iterate through players to find your target and you fire the remote event to that player to view their own character by what I am observing. Change re:FireClient(player, player.Character) to re:FireClient(starter, player.Character) and that may just do the trick :]