Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make this PlayerChatted script work?

I made a PlayerChatted script that works in the Play mode but doesnt work in game. I'm pretty sure this has something to do with FilteringEnabled (correct me if I'm wrong). Please help.

The script is supposed to delete one of two cars when I chat a command. It works in Play but not anything else.

passat = script.Parent.Passat
jeep = script.Parent["2016 Jeep Grand Cherokee"]
game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(msg)
	if player.Name == "richguyty" then
        if msg == "-passat" or msg == "keepjeep" then
			passat:Destroy()
			script:Destroy()
		elseif msg == "-jeep" or msg == "keeppassat" then
			jeep:Destroy()
			script:Destroy()
		elseif msg == "+bothcars" or msg == "keepbothcars" then
			script:Destroy()
        end
		end
    	end)
		end)

7 comments

0

Is "+bothcars" supposed to be "-bothcars"?

0

No, that line is mean't to keep both cars and delete the script. Sorry, I should have clarified that.

0

Have you tried turning off filtering enabled to check if that is the problem?

0

The only thing I can think of that would break that is your name not being richguyty when you try to use it. I don't think FilteringEnabled would affect it, based on this information: https://developer.roblox.com/en-us/api-reference/property/Workspace/FilteringEnabled

0

@Marty999 :xd: You can't turn off FE anymore; the property in studio is a dummy, and toggles whether "your game was updated to fe".

0

local script or script?

0

Script

1 answer

✓ Accepted answer

":connect" is deprecated. I'm pretty sure this would break something, since on "OnTouched" you needed to add another line of code under the end if you used :connect instead of :Connect.

passat = script.Parent.Passat
jeep = script.Parent["2016 Jeep Grand Cherokee"]
game.Players.PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(msg)
    if player.Name == "richguyty" then
        if msg == "-passat" or msg == "keepjeep" then
            passat:Destroy()
            script:Destroy()
        elseif msg == "-jeep" or msg == "keeppassat" then
            jeep:Destroy()
            script:Destroy()
        elseif msg == "+bothcars" or msg == "keepbothcars" then
            script:Destroy()
        end
        end
        end)
        end)

This discussion is preserved as it was. New answers, comments, and votes are closed.