This is also one of the options, but then if each elevator has its own value, it will have to do something like a module or somehow determine what needs to be done
Actually, that’s a smarter way of doing it, I believe. What if you instead make a ModuleScript that has separate functions/code for the client and server, and you just have the script execute those functions inside the script? Throwing some ideas here.
Well I tried to just put it in workspace at first, and that didn’t work.
So I think it has to do with the CS.Chatted
function.
Do you think you know how I would fix this?
I already have a module script to randomize, clone etc. the floors, but I already have a lot of floors so changing all of them would be a huge task.
You’re using CS.Changed
not CS.Chatted
.
.Changed
sends out an event when one of their properties gets changed.
.Chatted
should be obvious, but sends out an event when a player sends a message.
It won’t work! You need to connect an event to player
bruh, it was a typo all along.
But I did fix it and it didn’t seem to work, but I saw that it fires when CS:Chat() is fired. So how do I see when a player chats, without using PlayerAdded
and using a server script?
You can use RemoteEvent to get info from client to server?
Iterate over the players if you need to make exceptions and connect them to .Chatted
for _, v in pairs(game.Players:GetPlayers()) do
v.Chatted:Connect(function(msg, recipient)
--code
end)
end
Or use RemoveEvent
as @zamont124 said, but that again depends on your other code and it’s a mystery to know what works best for you.
Seems like it should give you the instance that it was chatted from.
You need to change the function parameters from what you have to best fit the above screenshot.
-- basically from this
CS.Chatted:Connect(function(msg)
...
end)
-- to this
CS.Chatted:Connect(function(part, msg, _ --[[you might not need the chat color]])
...
end)
And from the part, you just get the character from finding the FirstAncestorOfClass(“Model”) from that part.
Could you try and demonstrate that in a script? I don’t understand the “And from the part, you just get the character from finding the FirstAncestorOfClass(“Model”) from that part.”
Basically:
local ChatService = game:GetService("ChatService")
local Players = game:GetService("Player") -- to check if the character can be found from the player
CS.Chatted:Connect(function(part, msg, _)
local character = part:IsA("BasePart") and part:FindFirstAncestorOfClass("Model") or part
-- we do FindFirstAncestorOfClass("Model") to find the model that the part is a child/descendant of.
-- this is what you'd want to do to find the player's character when you're only presented with the part.
local player = character and Players:GetPlayerFromCharacter(character) or nil -- if the characte exists, check if there's a player that's attached to this character.
-- if not, or there isn't a player attached to it, return nil
if character and player then
-- your previous code goes here. but, for this example,
print(Player.Name, Player.UserId, character)
end
end
CS.Chatted:Connect(function(part, msg, _)
local character = part:IsA("BasePart") and part:FindFirstAncestorOfClass("Model") or part
local player = character and Players:GetPlayerFromCharacter(character) or nil
if character and player then
if msg == TheCharacter.Value then
door.Transparency = 0.75
door.Decal.Transparency = 0.75
door.CanCollide = false
task.wait(4)
door.Transparency = 0
door.Decal.Transparency = 0
door.CanCollide = true
else
print("Wasn't the corrent msg")
end
end
end)
This is what I put, and nothing worked.
The print didn’t print either.
If TheCharacter
is a model, then you’d want to do if character == TheCharacter.Value
.
No, TheCharacter
is a string. It’s what the player needs to chat.
The CS.Chatted function only fires when CS:Chat() is fired. Which is not when a player chats, rather an npc.
As already explained, you’re used .Changed, not .Chatted.
The problem with your code is that you’re trying to listen for ChatService.Chatted (an event games do not have the security level to operate on), when you should be listening for Player.Chatted.
You can read up on the code samples and explanations for this here.
Thank you guys for the support, but unfortunately the options you gave me didn’t work.
I solved it by using a script in ServerScriptService
and just using BindableEvents
to know when someone chats.
Thank you!
I would just like to point this out.
You did Changed, not Chatted.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.