|
| 02 Sep 2015 11:30 PM |
function onChatted(msg, recipient, speaker)
local source = string.lower(speaker.Name) msg = string.lower(msg) if string.sub(msg,1,2) == "g/" then if (speaker.leaderstats.Rank.Value == "Owner") or (speaker.leaderstats.Rank.Value == "Co-Owner") or (speaker.leaderstats.Rank.Value == "Staff") then if tostring(string.sub(msg, 3)) == "" or tostring(string.sub(msg, 3)) == " " then return end local namename = findPlayer(string.sub(msg, 3)) namename.storage.isGoalie.Value = true namename:LoadCharacter() end end end
function onPlayerEntered(newPlayer) newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end) end
function findPlayer(player) local NewPlayer = player:lower() for i, v in pairs(game.Players:GetChildren()) do if string.sub(NewPlayer, 1, string.len(NewPlayer)) == string.sub(v.Name:lower(), 1, string.len(player)) then return v else return nil end end end
function rGoaliesB() local plist = game.Players:GetChildren() for x = 1, #plist do if plist[x].TeamColor == game.Teams:findFirstChild("Blue").TeamColor then if plist[x].storage.isGoalie.Value == true then plist[x].storage.isGoalie.Value = false plist[x]:LoadCharacter() end end end end
function rGoaliesR() local plist = game.Players:GetChildren() for x = 1, #plist do if plist[x].TeamColor == game.Teams:findFirstChild("Red").TeamColor then if plist[x].storage.isGoalie.Value == true then plist[x].storage.isGoalie.Value = false plist[x]:LoadCharacter() end end end end
ok so heres the problem, script works in studio but very stupidly works in game. No errors pop up on server log when I do it and it doesn't work so I am at a loss. What happens is the first of the admins to join gets to use the command but only on themselves so like if it was me, "g/sil" works on me, but no one else's names work with it and the other admins can't use unless they joined before me, then I can't use it |
|
|
| Report Abuse |
|
|
UFAIL2
|
  |
| Joined: 14 Aug 2010 |
| Total Posts: 6905 |
|
|
| 03 Sep 2015 08:50 AM |
--ALWAYS USE PRINTS TO FIND THE ERROR --may be tedious online, but if just adding them when writing --the code you could of identified the error(or at least know where)
--find your style when using string manipulation --if you want to treat strings at classes call methods on them --if it's easier for you to read or understand just call the string class
--changed all instances where you used Players::GetChildren() to --Players::GetPlayers()
function onChatted(msg, recipient, speaker)
local source = string.lower(speaker.Name) msg = string.lower(msg) if string.sub(msg,1,2) == "g/" then if (speaker.leaderstats.Rank.Value == "Owner") or (speaker.leaderstats.Rank.Value == "Co-Owner") or (speaker.leaderstats.Rank.Value == "Staff") then if tostring(string.sub(msg, 3)) == "" or tostring(string.sub(msg, 3)) == " " then return end local namename = findPlayer(string.sub(msg, 3)) namename.storage.isGoalie.Value = true namename:LoadCharacter() end end end
function onPlayerEntered(newPlayer) newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end) end
function findPlayer(player) local NewPlayer = player:lower() for i, v in pairs(game.Players:GetPlayers()) do --You were using string.sub on NewPlayer to get the whole string --Returns the same thing --[[**MAJOR ERROR** once calling return it ends the function, since you've "found" the values you've been searching for what i'm assuming is it it wasn't working becase of it ending on the first player who entered ]] --[[**SOLUTION** Call 'return nil' after the loop, since that would mean no matches were found. It won't fire otherwise since the function has already returned the value --]] if NewPlayer == string.sub(v.Name:lower(), 1, string.len(player)) then return v end end return nil end
function rGoaliesB() local plist = game.Players:GetPlayers() for x = 1, #plist do if plist[x].TeamColor == game.Teams:findFirstChild("Blue").TeamColor then if plist[x].storage.isGoalie.Value == true then plist[x].storage.isGoalie.Value = false plist[x]:LoadCharacter() end end end end
function rGoaliesR() local plist = game.Players:GetPlayers() for x = 1, #plist do if plist[x].TeamColor == game.Teams:findFirstChild("Red").TeamColor then if plist[x].storage.isGoalie.Value == true then plist[x].storage.isGoalie.Value = false plist[x]:LoadCharacter() end end end end |
|
|
| Report Abuse |
|
|
|
| 03 Sep 2015 09:13 AM |
| Fully rewriting brb.. and that would still return only the first thing since using return multiple times doesnt work unless the function calling it is prepared for multiples. |
|
|
| Report Abuse |
|
|
| |
|
|
| 03 Sep 2015 10:35 AM |
ty ufail for that advice, the reason i was having so many problems with it is because half of the script i tried to implement from someone else's script and I don't yet understand those scripts. I completely rewrote the whole thing in a way that I understand and it works perfectly. Thank you for you help.
here is the script if you're interested : ___________________________________
game.Players.PlayerAdded:connect(function(player) --if group[player.Name] then player.Chatted:connect(function(msg) if string.sub(msg,1,2) == "g/" then if isStaff(player) then local namename = findPlayer(string.sub(msg,3)) print(namename.Name) namename.storage.isGoalie.Value = true namename:LoadCharacter() end end end) --end end)
function findPlayer(name) local list = game.Players:GetPlayers() for p = 1, #list do local person = list[p] for x = 1, string.len(name), 1 do print(x) local st1 = string.sub(list[p].Name,1,x) local st2 = string.sub(name,1,x) local st11 = string.lower(st1) local st22 = string.lower(st2) print(st11) print(st22) if st11 == st22 then print(person) return person end end end return end
function isStaff(player) if (player.leaderstats.Rank.Value == "Owner") or (player.leaderstats.Rank.Value == "Co-Owner") or (player.leaderstats.Rank.Value == "Staff") then return true else return false end end
function rGoaliesR() local plist = game.Players:GetChildren() for x = 1, #plist do if plist[x].TeamColor == game.Teams:findFirstChild("Red").TeamColor then plist[x].storage.isGoalie.Value = false end end end
function rGoaliesB() local plist = game.Players:GetChildren() for x = 1, #plist do if plist[x].TeamColor == game.Teams:findFirstChild("Blue").TeamColor then plist[x].storage.isGoalie.Value = false end end end |
|
|
| Report Abuse |
|
|