Revelted
|
  |
| Joined: 02 Nov 2014 |
| Total Posts: 503 |
|
|
| 26 Jan 2017 04:39 PM |
deb = true
function ontouch(plr) if deb == false then return end deb = false if workspace:FindFirstChild(plr) then workspace.plr.Humanoid.JumpPower = 0 deb = true end end
script.Parent.Touched:connect(ontouch)
i just cant for the life of me figure out arguements ( the thing in the brackets after the function )!! does anyone have a good youtube video that explains it, or if someones good at explaining it plz do!
Also, if you guys could correct my script q.q |
|
|
| Report Abuse |
|
|
|
| 26 Jan 2017 05:08 PM |
local deb=false
local function touched(hit)--hit is what actually touched the brick if not deb then deb=true local p=game.Players:GetPlayerFromCharacter(hit.Parent) if p then --did it find a player? hit.Parent.Humanoid.JumpPower=0 end deb=false end end
script.Parent.Touched:Connect(touched)
|
|
|
| Report Abuse |
|
|
iiNemo
|
  |
| Joined: 22 Jul 2013 |
| Total Posts: 2380 |
|
|
| 26 Jan 2017 05:09 PM |
script.Parent.Touched:connect(function(hit) end) -- This is prettier looking.. |
|
|
| Report Abuse |
|
|
|
| 26 Jan 2017 05:13 PM |
| An argument is nothing more than information being passed into a function you are calling. Example local function example(x) return (x + 10); end print(example(6)) --[[> 16, because it ran the code in my function where x was 6.]] function ontouch(plr) So on this line you are creating a new function that takes the argument 'plr' script.Parent.Touched:connect(ontouch) This line right here will call the function 'ontouch' whenever it's parent is touched. When it calls the function it will pass an argument, the argument will be the part that touched it. You picked plr as your argument and it will work fine, because you can name the argument basically anything you want, but it will not be a player, it will be a part. Now if that part is a #### ##### you can use the #### #### to figure out who the player who touched it is. |
|
|
| Report Abuse |
|
|
| |
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 26 Jan 2017 05:47 PM |
@New wrong.
@OP
local part = script.Parent local debounce = false
part.Touched:connect(function(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player and not debounce then local char = player.Character local human = char:WaitForChild('Humanoid') debounce = true human.JumpPower = 0 wait(1) debounce = false end end)
|
|
|
| Report Abuse |
|
|
Revelted
|
  |
| Joined: 02 Nov 2014 |
| Total Posts: 503 |
|
|
| 26 Jan 2017 08:13 PM |
if workspace.a.BrickColor == "Bright green" and workspace.b.BrickColor == "Bright green" then wait (3) workspace.c:Destroy() end
im new with the function "and" and Im not sure how to use it properly, could someone link a lua wiki or tell me how it works?
|
|
|
| Report Abuse |
|
|
Revelted
|
  |
| Joined: 02 Nov 2014 |
| Total Posts: 503 |
|
|
| 26 Jan 2017 08:14 PM |
And thanks to the above for the help with arguements!!! i understand it now
|
|
|
| Report Abuse |
|
|
|
| 26 Jan 2017 08:42 PM |
https://twitter.com/128Gigabytes/status/698367741674192896
Basically when you use "and" if one of the 2 things is nil or false, the whole thing will be false.
if (true and false) then
Is the same as if false then
if (false and true) then
Is the same as if false then
if (true and true) then
is the same as if true then
if (true and 1) then
is the same as if true then (Because 1 is not false or nil.)
|
|
|
| Report Abuse |
|
|
Revelted
|
  |
| Joined: 02 Nov 2014 |
| Total Posts: 503 |
|
|
| 26 Jan 2017 09:07 PM |
| So i was far off when I wrote my script wasnt I q.q |
|
|
| Report Abuse |
|
|
|
| 26 Jan 2017 09:18 PM |
No your script is fine, except you are comparing a BrickColor to a string
That would be like if I said
if ("1" == 1) then print("Hello world.") end
Well a string will never be the same as a number.
So do this
if workspace.a.BrickColor.Name == "Bright green" and workspace.b.BrickColor.Name == "Bright green" then
|
|
|
| Report Abuse |
|
|
Revelted
|
  |
| Joined: 02 Nov 2014 |
| Total Posts: 503 |
|
|
| 26 Jan 2017 10:33 PM |
ok it works when they both are put as green, but i have this script in a and b
function ontouch(plr) if plr.Parent:FindFirstChild("Humanoid") then script.Parent.BrickColor = BrickColor.new("Bright green") end end
script.Parent.Touched:connect(ontouch)
when it makes it green tho, it doesnt work why? |
|
|
| Report Abuse |
|
|
|
| 26 Jan 2017 10:44 PM |
It is still working you just can not see the difference, if you make a green object green, you won't see a difference.
|
|
|
| Report Abuse |
|
|
Revelted
|
  |
| Joined: 02 Nov 2014 |
| Total Posts: 503 |
|
|
| 26 Jan 2017 11:02 PM |
| how do i make it so i can see the difference? |
|
|
| Report Abuse |
|
|
|
| 26 Jan 2017 11:19 PM |
Well one option would be to check if the thing is already green, and if it is, make it another color.
local function ontouch(plr) if plr.Parent:FindFirstChild("Humanoid") and (script.Parent.BrickColor.Name ~= "Bright green") then script.Parent.BrickColor = BrickColor.new("Bright green") elseif plr.Parent:FindFirstChild("Humanoid") then script.Parent.BrickColor = BrickColor.new("Bright red") end end
script.Parent.Touched:connect(ontouch)
|
|
|
| Report Abuse |
|
|
Revelted
|
  |
| Joined: 02 Nov 2014 |
| Total Posts: 503 |
|
|
| 26 Jan 2017 11:45 PM |
Just a couple of questions,
1) Whats the ~ mean before the =
2) i havent really learnt about elseif's ( but i have some notion)
3) since the statment after the and is false, wouldnt it revert to the first one?
thats all |
|
|
| Report Abuse |
|
|
|
| 26 Jan 2017 11:51 PM |
~= is the opposite of ==
== means is equal to
~= means is not equal to
1 == 2 is false
1 ~= 2 is true
Not sure what you mean by revert back if plr.Parent:FindFirstChild("Humanoid") and (script.Parent.BrickColor.Name ~= "Bright green") then
This means there has to be a humanoid and the brick also has to be any color besides Bright green
|
|
|
| Report Abuse |
|
|
|
| 27 Jan 2017 01:37 AM |
@TimeTicks
how am I wrong. You are using hit.Parent in the GetPlayersFromCharacter so if it finds a player then hit.Parent must be a character. The only difference you did was add a wait(1) and add an extra variable name.
|
|
|
| Report Abuse |
|
|
|
| 27 Jan 2017 05:56 PM |
Let me clear it up for you, I'm pretty sure this is what he meant
iiNemo: -- This is prettier looking..
newcoolman2: @Nemo I disagree.
TimeTicks: @New wrong.
Although to be fair he might have meant your script is wrong, because the wait in the script is actually very important in making the debounce work.
|
|
|
| Report Abuse |
|
|
Revelted
|
  |
| Joined: 02 Nov 2014 |
| Total Posts: 503 |
|
|
| 30 Jan 2017 12:00 AM |
So I did that script you made, and put it into both a and b blocks, but even then when they go green, the script if workspace.a.BrickColor.Name == "Bright green" and workspace.b.BrickColor.Name == "Bright green" then wait(2) workspace.c.CanCollide = false workspace.c.Anchored = false end doesnt wanna work |
|
|
| Report Abuse |
|
|
|
| 30 Jan 2017 01:10 AM |
Your script only checks if they are both green once, you will need to continuously check the colors so when they changed your script will do its thing.
|
|
|
| Report Abuse |
|
|
Revelted
|
  |
| Joined: 02 Nov 2014 |
| Total Posts: 503 |
|
|
| 31 Jan 2017 09:02 PM |
So i need to add a loop?
or an elseif?
im confused >.< |
|
|
| Report Abuse |
|
|
|
| 31 Jan 2017 09:06 PM |
| Add a 'while true do' at the beginning. |
|
|
| Report Abuse |
|
|
Revelted
|
  |
| Joined: 02 Nov 2014 |
| Total Posts: 503 |
|
|
| 31 Jan 2017 09:07 PM |
| I tried that, but It still doesnt work |
|
|
| Report Abuse |
|
|
Revelted
|
  |
| Joined: 02 Nov 2014 |
| Total Posts: 503 |
|
|
| 31 Jan 2017 09:09 PM |
| NVM turns out its just attached to the ground XDDD |
|
|
| Report Abuse |
|
|