Hello! I would like to ask a question (or help at this point).
Is it possible to replace player’s model with a command in chat, example like:
if player texts in chat /e modelchange, their model is now a selected rig!
you can use the Player.Chatted
Event to detect when a player sends something in chat, and then you can check if it is the command you’re looking for.
local players = game:GetService "Players"
players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
if string.sub(msg, 1, 1) ~= '/' then return end --check if message begins with / to indicate a command
local command = string.sub(msg, 1, -1)
if command ~= "modelswitch" then return end --check for command
local model = --your model
:Clone()
model:PivotTo(plr.Character.PrimaryPart.CFrame)
plr.Character = model
end)
end)
alternatively you can use TextChatCommand
s, which intercept player messages and fire their TextChatCommand.Triggered
Event when the message is invoking the command using the ‘/’.
Note: When you use the Chatted event the command still appears in chat, but using TextChatCommand
they are not replicated.
-
Step one:
Create aTextChatCommand
in TextChatService using the ‘+’ icon in Roblox Studio or using Instance.new in a Script -
Step two
Open a new LocalScript and subscribe to the triggered event:
local TextChatService = game:GetService "TextChatService"
local player = game.Players.LocalPlayer
local command = TextChatService.YourCommand
local model = --your model
command.Triggered:Connect(function(origin: string, unfiltered: string)
--do processing here
--you can use the unfiltered string passed to this fn to check for arguments.
local clone = model:Clone()
clone:PivotTo(player.Character.PrimaryPart.CFrame) --move model to plr's position
--idk if you need to use remote events here
player.Character = clone
end)
Since the latter runs in a local script you might need to use RemoteEvents depending on where the model is located. I haven’t tested this.
Hope this helps!