Hey, trying to make a view command and it isn’t working. Mind helping me?
Code (ModulE Script):
local Players = game:GetService("Players")
local PlayerFromName = require(script.Parent.Parent.PlayerFromName)
local rs = game:GetService("ReplicatedStorage")
local event = rs.Events.viewEvent
return function (admin, splitMessage)
local viewPlayerName = splitMessage[2]
local viewPlayer = PlayerFromName(admin, viewPlayerName)
local camera = workspace.CurrentCamera
if not viewPlayer then
return
end
event:FireClient(viewPlayer, camera, viewPlayer)
end
Local Script:
local rs = game:GetService("ReplicatedStorage")
local event = rs.Events.viewEvent
event.OnClientEvent:Connect(function(player, cam, playerName)
local viewPlayer = tostring(playerName)
local character = workspace[tostring(player)]
cam.CameraSubject = character.Humanoid
end)
That’s odd. Sorry for nagging about variables and stuff, but what is viewPlayerName, splitMessage, and the module script PlayerFromName? It also might be helpful if you send the PlayerFromName module script.
viewPlayername is the variable and gets the splitMessage from the command.
Ex: /view me splitmessage would be “me”
Here you go!
local Players = game:GetService("Players")
return function (admin, nameFragment)
if nameFragment == "me" then
return admin
end
local allPlayer = Players:GetPlayers()
for _, player in allPlayer do
local playerName = player.Name:lower()
local namesMatch = playerName:sub(1, #nameFragment) == nameFragment
if namesMatch then
return player
end
end
end
I think the problem is the variable splitMessage. Can you explain exactly what it is? I don’t really know what it is, but all I think I know is that it is a table.
Sorry, but just to make sure I’m correct, splitMessage is the chat message the player has sent? Like if the player says “Turkey”, splitMessage would be “Turkey”. Or do you mean the players sees a message on the screen, which would be split message.
This is because you cannot access the workspace.CurrentCamera on the server. You have to call out this property on the client. Oh, and I don’t see you changing the CameraType to Scriptable.