Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Im trying to make the bodyposition move when a certain person says a phrase. Why isnt this working?

Asked by 9 years ago

This is my script, and nothing pops up about an error in output either

door = game.Workspace.LobbyDoor
local player = game.Players:FindFirstChild("Humanoid")
End = game.Workspace.EndLob


function test(name)
    if player.Name == "koolkid8099, Player" then
        player:connect(onChatted)
    end
end

function onChatted(msg, recipient, speaker) 



local source = string.lower(speaker.Name) 
msg = string.lower(msg) 

if (msg == "open/lobby") then
    door.CanCollide = false
    door.BodyPosition.position = End.Position 
wait(2)
    door.CanCollide = true

end 

end 

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

game.Players.ChildAdded:connect(onPlayerEntered) 


1
Fix your code format, please. Goulstem 8144 — 9y
1
ogm git gud nub1111 Perci1 4988 — 8y

1 answer

Log in to vote
1
Answered by 9 years ago

Firstly, you shouldn't be defining your variables like that. Secondly, game.Workspace:FindFIrstChild("Humanoid") is not going to give you a player. If you gave it a second argument set to true, it'd look through everything within everything for a humanoid, but that's your player's character's humanoid - not the player.

You also don't check strings in that way. In addition, you should probably debounce so that you cant keep opening it when it's already opening.

What you want to do is have an event listener waiting for a player to join, and then waiting for that player to speak, then looping through a table of names to see if it returns true:

admins = {"FlyScript", "koolkid8099", "Player", "etc"}
door = game.Workspace.LobbyDoor
status = "closed"

function nameCheck(name)
    local valid
    for _, v in pairs(admins) do
        if v == name then
            valid = true
        end
    end
    return valid
end

game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(m)
        if nameCheck(player.Name) and m == "open/lobby" and status == "closed" then
            status = "opening"
            door.BodyPosition.position = game.Workspace.EndLob.Position
            door.CanCollide = false
            wait(2)
            door.CanCollide = true
            status = "open"
        end
    end)
end)

You'd do a similar sort of thing for closing the door.

Ad

Answer this question