CS.Changed:Connect(function(msg) -- (CS = ChatService)
if msg == TheCharacter.Value then
door.Transparency = 0.75
door.CanCollide = false
task.wait(4)
door.Transparency = 0
door.CanCollide = true
end
end)
This script doesn’t work. I’m trying to see if the msg that the player chatted is the same as TheCharacter Value.
The reason I suspect it’s not working is because the place where this is, is inside of ReplicatedStorage and doesn’t get pulled out till later in the game.
So Players.PlayerAdded:Connect(function() end) (to get the player) wouldn’t work because scripts don’t run in ReplicatedStorage.
I think the problem here is the script isn’t executing once it’s cloned, which is what I think you’re doing. So you might have to re-parent the script to the model of the floors AFTER they’re moved from the ReplicatedStorage to the workspace.
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.
.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.
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?
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.”
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.