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

Visible script won’t as I intended help?

Let me explain how it was supposed to work.

If you say “stuff” in an in-game chat and you username is “raid6n” a GUI will be enabled

    local message = "stuff"
function onChatted(msg, recipient, speaker)
    local source = string.lower(speaker.Name)
    msg = string.lower(msg)
    if (msg == message) and player.Name == "raid6n" then
        for i = 1, 9 do
            script.Parent.Enabled = true
            wait()
        end
    end
end

function onPlayerEntered(newPlayer)
    newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end)
end

game.Players.PlayerAdded:connect(onPlayerEntered)

No errors

4 comments

0

it’s a local script

0

set player

0

Did you even script this?

0

no

1 answer

✓ Accepted answer

I'm seeing A LOT of problems on your code. I recommend checking every single error you done while scripting this, and if you didn't script it, you won't learn.

There's a lot to improve.

local message = "stuff"
function onChatted(msg, recipient, speaker)
    local source = string.lower(speaker.Name)
    msg = string.lower(msg)
    if (msg == message) and player.Name == "raid6n" then -- "player" is supposed to be "speaker"
        for i = 1, 9 do -- Why iterate nine times? Also, this will fire every time you say "stuff", which will keep enabling the gui while it's enabled already.
            script.Parent.Enabled = true
            wait() -- No point on using wait()
        end
    end
end

function onPlayerEntered(newPlayer)
    newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end)
end

game.Players.PlayerAdded:connect(onPlayerEntered) -- You're not firing the function, you're setting a value's name
												  -- Local scripts only function after your character load, so this will not detect you, but other players

Here's the fixed script:

local message = "stuff"
local LocalPlayer = game.Players.LocalPlayer

function onChatted(msg, recipient, speaker)
    local source = string.lower(speaker.Name)
    msg = string.lower(msg)

    if (msg == message) and speaker.Name == "raid6n" then
		script.Parent.Enabled = true
    end
end

function onPlayerEntered(newPlayer)
    newPlayer.Chatted:Connect(function(msg, recipient)
		onChatted(msg, recipient, newPlayer)
	end)
end

onPlayerEntered(LocalPlayer)

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