Module Script to Local Script Issue (Via. Rem. Event)

I’ve attempted at making a command under the name “:Watch”, it’s supposed to set the player’s camera to the target’s character, however I tried to make it in the module script, it didn’t work, I also tried making int via LocalScript connected from the Mod. Script via a remote event in Replicated Storage.

LOCAL SCRIPT:

game.ReplicatedStorage.Remote.OnClientEvent:Connect(function(target, player)
	
	game.Workspace.CurrentCamera.CameraSubject = target.Humanoid
end)

SERVER SCRIPT:

function command.exec(player: "Player model.", args: "Arguments.", RankPermission: "Admin level", cmd)

	local function get_player(player_name)
		local lower_player_name = string.lower(player_name)
		for _, player in pairs(game.Players:GetPlayers()) do
			if player.Name:sub(1,#player_name):lower() == lower_player_name then
				return player
			end
		end
	end

	local target = nil
	if args[2] then target = get_player(args[2]) else target = player end
	
	game.ReplicatedStorage.Remote:FireClient(target, player)


end

after doing “:watch Vx_ney” (My friend) nothing happens. I’ve tried everything I know how to fix this, however I couldn’t come up with a fix, so I went here, to the DevForum to ask for help or improvement or suggestions.

Kind Regards,
VladPhonkie

The script that handles the player who send the command on chat?
The script that is calling that function command.exec()

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		
		
		local args = message:split(" ")
		local plrrank = 0
		plrrank = script.Admins:FindFirstChild(player.Name).Value
		
		
		for _,v in pairs(Cmds:GetChildren()) do
			local cmd = require(v)
				
			
			if args[1] == ":" .. cmd.info().Name and  plrrank >= cmd.info().RankPerm and cmd.info().Enabled == true then
				cmd.exec(player, args, plrrank, cmd, message)
				require(script.AssistantModule).addLog(player.Name, message)
			end
		end
	end)
end)

Your are using the Legacy Chat Service or the Text Chat Service? (the new one)

Yeah, but it doesn’t affect other commands, other commands work perfectly fine.

OK, so you are using the Legacy one? cause Chatted event doesnt work with the new TextChatService, I just wanted to know before reading your scripts.

Well uh… as I said above, they work perefectly fine.

in this like the target refers to theplayer who will recieve the re and over here

you are adding another target so your are giving 1 think but the scripts wants 2 so just add another target b/w target and player in the module script.

So

game.ReplicatedStorage.Remote.OnClientEvent:Connect(function(target1, target, player)

?

wait… sorry here:

game.ReplicatedStorage.Remote:FireClient(player,target) -- module
game.ReplicatedStorage.Remote.OnClientEvent:Connect(function(target)

Alright, I’ll try this then, hand me a moment.

Nothing seems to happen again, I’ve even added a print(“A”) argument to see if it’d print anything, however still nothing happens.

--- LOCALSCRIPT

game.ReplicatedStorage.USARYAdminRemote.OnClientEvent:Connect(function(target, player)
	
	print("A")
	game.Workspace.CurrentCamera.CameraSubject = target.Humanoid
end)
-- MODULESCRIPT

function command.exec(player: "Player model.", args: "Arguments.", RankPermission: "Admin level", cmd)

	local function get_player(player_name)
		local lower_player_name = string.lower(player_name)
		for _, player in pairs(game.Players:GetPlayers()) do
			if player.Name:sub(1,#player_name):lower() == lower_player_name then
				return player
			end
		end
	end

	local target = nil
	if args[2] then target = get_player(args[2]) else target = player end
	
	game.ReplicatedStorage.USARYAdminRemote:FireClient(player,target)
end

return command

are you then even calling command.exec? if its not printing anything with a if then maybe its because the function isnt working. try using fire all clients and then tell me if it still prints.

Turns out that the Local script needs to be in PlayerCharacterScripts, I believe. Let me try that.

Seems that you are sending a Player instance to the LocalScript, but in the local script you are dealing with the Player Instance as a Character Model, trying to get the Humanoid from the Player but the Humanoid is in Character Model

This indeed is a Player Instance:

		for _, player in pairs(game.Players:GetPlayers()) do
			if player.Name:sub(1,#player_name):lower() == lower_player_name then
				return player -- Player Instance
			end
		end

target variable is holding that Player Instance:
target = get_player(args[2])

You are firing the client sending the player instance not the character:
game.ReplicatedStorage.Remote:FireClient(target, player)

In the client should be:

game.ReplicatedStorage.Remote.OnClientEvent:Connect(function(target, player)
	game.Workspace.CurrentCamera.CameraSubject = target.Character.Humanoid
end)

I was right, the local script needs to be in starterplayerscripts/startercharacterscripts, I don’t know why, but I guess now it works. Thank you both for your time thought.

wait oof okay no problem glad to help.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.