generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Explain how I can do this

Previous Thread :: Next Thread 
Surgo is not online. Surgo
Joined: 11 Jan 2011
Total Posts: 2748
21 Jul 2014 09:49 PM
So I'm making a script that when you say a number 10-35, that's how many kills player team will have to get to 'win'.

I was thinking that I would have to make a value in the script.

But what I don't know how to do it tell the script that a number 10-35 has been chosen.
Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
21 Jul 2014 09:50 PM
You mean when someone chats that number in-game, that becomes how many kills are required?
Report Abuse
blox6137 is not online. blox6137
Joined: 23 Nov 2008
Total Posts: 1109
21 Jul 2014 09:51 PM
I don't understand your question.
Report Abuse
connor954 is not online. connor954
Joined: 24 Jul 2008
Total Posts: 947
21 Jul 2014 09:52 PM
Well, first you have to set "who" can do this.
Report Abuse
Surgo is not online. Surgo
Joined: 11 Jan 2011
Total Posts: 2748
21 Jul 2014 09:57 PM
All I've really figured out is this:

admins = {"Surgo"}

function isAdmin(name)
for i,v in pairs(admins) do
if name:lower() == v:lower() then return true end
end
return false
end


local door=script.Parent
game.Players.PlayerAdded:connect(function(p)
if isAdmin(p.Name) then
p.Chatted:connect(function(msg)
if msg=="TEXT" then
end
end)
end
end)
Report Abuse
Surgo is not online. Surgo
Joined: 11 Jan 2011
Total Posts: 2748
21 Jul 2014 10:00 PM
For the text part, I actually need it to be like "!load_TDM_10"

So I was thinking I would have to make it something like:

if msg=="!load_"..."TMD_"..."10" then


Report Abuse
UncleTaz is not online. UncleTaz
Joined: 19 Aug 2009
Total Posts: 12795
21 Jul 2014 10:02 PM
Okay first, the number of wins should be a IntValue so it can be accessed back and forth.

Then once the number is said, Use tostring(tonumber) and that number would be the value of the IntValue
Report Abuse
Surgo is not online. Surgo
Joined: 11 Jan 2011
Total Posts: 2748
21 Jul 2014 10:21 PM
Don't understand this tonumber thing...

"Tries to convert its argument to a number. If the argument is already a number or a string convertible to a number, then tonumber returns this number; otherwise, it returns nil."

Like what
Report Abuse
blox6137 is not online. blox6137
Joined: 23 Nov 2008
Total Posts: 1109
21 Jul 2014 10:24 PM
var1 = 1 -- number
var2 = "1" -- string

print(var1 .. var2)-- this would make error, as you cant concatenate numbers.

So, you would do:
print(tonumber(var2) + var1), or
print(tostring(var1) .. var2)
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
21 Jul 2014 10:26 PM
'var1 = 1 -- number
var2 = "1" -- string

print(var1 .. var2)-- this would make error, as you cant concatenate numbers.'

No it doesn't error it outputs 11
Report Abuse
blox6137 is not online. blox6137
Joined: 23 Nov 2008
Total Posts: 1109
21 Jul 2014 10:27 PM
It produces an error in the IDE that I use, so it must be different with ROBLOX's.
Report Abuse
blox6137 is not online. blox6137
Joined: 23 Nov 2008
Total Posts: 1109
21 Jul 2014 10:30 PM
Just researched, and it's a bug with the IDE I use, not an error in the script.
MY BAD.
Report Abuse
Surgo is not online. Surgo
Joined: 11 Jan 2011
Total Posts: 2748
21 Jul 2014 10:34 PM
Why am I adding? And WHAT am I adding?
Report Abuse
Surgo is not online. Surgo
Joined: 11 Jan 2011
Total Posts: 2748
21 Jul 2014 10:41 PM
Am I adding 10 and 35?
Report Abuse
blox6137 is not online. blox6137
Joined: 23 Nov 2008
Total Posts: 1109
21 Jul 2014 10:43 PM
No, just ignore me and my comments.
Report Abuse
ArbiterOfDeath is not online. ArbiterOfDeath
Joined: 20 Jun 2011
Total Posts: 1458
21 Jul 2014 10:49 PM
You know you will need three things for this. First, you will need a variable to store the kill goal. Second, you will need a variable to store the kills made so far. Third, you know that you will have to connect to the Player.Chatted event. When the player chats, check their chat for a number. It should look like this:

local killsCurrent = 0
local killsGoal

local function onChatted(message)
local goal = message:match "^(%d+)&"
if not killsGoal and goal then
killsGoal = goal
end
end

local function onDied()
killsCurrent = killsCurrent + 1
end

local function onCharacterAdded(character)
character:WaitForChild("Humanoid").Died:connect(onDied)
end

local function onPlayerAdded(player)
player.Chatted:connect(onChatted)
player.CharacterAdded:connect(onCharacterAdded)
end

game:GetService("Players").PlayerAdded:connect(onPlayerAdded)
Report Abuse
COOLDUDE11OO is not online. COOLDUDE11OO
Joined: 21 Aug 2011
Total Posts: 5115
21 Jul 2014 10:52 PM
tostring turns given argument into a string
tonumber turns given arguments into a number
ex:

local ex1='1'
local ex2=1
print(type(ex1),type(ex2))
>String Number

ex1=tonumber(ex1)
print(type(ex1))
>Number
ex2=tostring(ex2)
print(type(ex2))
>String

You can also use these with if statements to see if given arguments can be turned into a string or number.
local s='Hello world!'

if tonumber(s) then print('It works!')
else print("It isn't possible!")
end

>

Nothing. Now, try changing the variable. If you make its contents numbers, it will print 'It works!'

local s='1'

if tonumber(s) then print('It works')
else print("It isn't possible!")
end

>It works!
Report Abuse
Surgo is not online. Surgo
Joined: 11 Jan 2011
Total Posts: 2748
21 Jul 2014 11:04 PM
So if s='2'

Then Print would be:
>It works!
>It works!

???
Report Abuse
ArbiterOfDeath is not online. ArbiterOfDeath
Joined: 20 Jun 2011
Total Posts: 1458
21 Jul 2014 11:13 PM
By popular request, let me edit my code to do what he asked for:

ocal killsCurrent = 0
local killsGoal

local function onChatted(message)
local goal = tonumber(message:match "^(%d+)&")
if not killsGoal and goal and goal >= 10 and goal <= 35 then
killsGoal = goal
end
end

local function onDied()
killsCurrent = killsCurrent + 1
end

local function onCharacterAdded(character)
character:WaitForChild("Humanoid").Died:connect(onDied)
end

local function onPlayerAdded(player)
player.Chatted:connect(onChatted)
player.CharacterAdded:connect(onCharacterAdded)
end

game:GetService("Players").PlayerAdded:connect(onPlayerAdded)
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image