Ad
Log in to vote
0

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

Asked by 2 days 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 15 — 1d

3 answers

Log in to vote
0
Answered by 2 days ago
Edited 2 days 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
sO_Ov 195
2 days ago
Edited 2 days 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 — 1d
Log in to vote
0
Answered by 1 day ago
Edited 1 day 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