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

When I type the command out nothing happens, how can I fix this?

Asked by 3 years ago
local plr = game.Players.LocalPlayer
local fo = game.ReplicatedStorage.Football
game.Players.PlayerAdded:Connect(function(plr) -- Detects player joining and stores player object at the var "plr"
    plr.Chatted:connect(function(msg) -- Detects when a player chats and stores the message to the var "msg"
        msg = msg:lower()
        if (msg == ":give me fo") then-- Checks if what player chatted is the command(in this case, startgam --start the game

            fo:Clone()
            fo:Clone().Parent = plr
        end 

ServerScriptService.Script:10: Expected 'end' (to close 'function' at line 4), got <eof>; did you forget to close 'then' at line 6? Error

0
Line 9, you forgot the backpack The_Saver31 260 — 3y

3 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Try this:

local plr = game.Players.LocalPlayer local fo = game.ReplicatedStorage.Football local prefix = ':' game.Players.PlayerAdded:Connect(function(plr) plr.Chatted:connect(function(msg) msg = msg:lower() if string.sub(msg, 1, 11) == prefix..'give me fo' then fo:Clone() fo:Clone().Parent = plr end end) end)

or try this:

local plr = game.Players.LocalPlayer local fo = game.ReplicatedStorage.Football local prefix = ':' game.Players.PlayerAdded:Connect(function(plr) plr.Chatted:connect(function(msg) msg = msg:lower() if msg == prefix..'give me fo' then fo:Clone() fo:Clone().Parent = plr end end) end)

Ad
Log in to vote
0
Answered by
174gb 290 Moderation Voter
3 years ago
Edited 3 years ago

1 - You can't use 'game.Players.LocalPlayer' from server scripts,

2 - You need close your functions

try it and should work

local Players = game:GetService("Players")
local fo = game.ReplicatedStorage.Football

Players.PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(msg)
        msg = msg:lower()
        print(msg)
        if (msg == ":give me fo") then
            fo:Clone()
            fo:Clone().Parent = plr
        end 
    end)
end)
0
Thank you!!! Patriq_Kane 8 — 3y
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Try This One

local plr = game.Players.LocalPlayer
local fo = game.ReplicatedStorage.Football

game.Players.PlayerAdded:connect(function(player) 
    if player.Name == "Player" then 
            player.Chatted:connect(function(msg)
            if msg:lower() == ":give me fo" then
                local fooo = fo:Clone()
                fooo.Parent = plr.Backpack --You forgot the Backpack mate
            end
        end)
    end
end)

Answer this question