|
| 03 Nov 2016 04:13 PM |
| I am trying to make a king of the hill game, but i cannot get the hill to work. if i make it Ontouched, i cannot make it give out points every second as i want to, because the script only fires when touched. how can i make this work? |
|
|
| Report Abuse |
|
|
| |
|
|
| 03 Nov 2016 04:16 PM |
| This does not work, as the script only runs when touched. |
|
|
| Report Abuse |
|
|
|
| 03 Nov 2016 04:18 PM |
local buttonPressed = false --Store whether the button is pressed in a local variable local stored = 0 while stored < 50 do stored = stored + 1 end function onTouched(hit) if not buttonPressed then -- Is it not pressed? buttonPressed = true -- Mark it as pressed, so that other handlers don't execute local cash = game.Players:findFirstChild(hit.Parent.Name).leaderstats.Cash cash.Value = cash.Value + 1
wait (1) -- Do Stuff buttonPressed = false -- Mark it as not pressed, so other handlers can execute again end end script.Parent.Touched:connect(onTouched) attempted script for refrence
|
|
|
| Report Abuse |
|
|
Cytheur
|
  |
| Joined: 12 Aug 2014 |
| Total Posts: 7328 |
|
|
| 03 Nov 2016 04:21 PM |
Sorry a lot of this was tl;dr and all.
But what it sounds like you're trying to do is give points to everybody that is currently on the hill and such. Correct?
Well I didn't even know about this, but try out GetTouchingParts()
It's an amazing function, and I'm pretty sure this will fix your problems.
R$565,401 |
|
|
| Report Abuse |
|
|
SurKipper
|
  |
| Joined: 25 Dec 2011 |
| Total Posts: 435 |
|
|
| 03 Nov 2016 04:23 PM |
local beingTouched = false local player = nil
function loop() while beingTouched and player ~= nil do wait(1) --award player points if beingTouched == false or player == nil then break end end end
part.Touched:connect(function(hit) if player then return end local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid then local plr = game.Players:GetPlayerFromCharacter(hit.Parent) if plr then beingTouched = true player = plr loop() end end end
part.TouchEnded:connec(function(hit) local plr = game.Players:GetPlayerFromCharacter(hit.Parent) if plr == player then player == nil beingTouched = false end end |
|
|
| Report Abuse |
|
|
Cytheur
|
  |
| Joined: 12 Aug 2014 |
| Total Posts: 7328 |
|
|
| 03 Nov 2016 04:26 PM |
"I am trying to make a king of the hill game, but i cannot get the hill to work. if i make it Touched, i cannot make it give out points every second as i want to, because the script only fires when touched. how can i make this work?"
I actually read it now.
Say you had a timer for the match,
timer = 60
So the match time will take 60 seconds.
We'll use a while loop instead of a for loop, just so if you wanted to add other 'conclusion' options then you could.
while timer > 0 do wait(1) timer = timer - 1 -- Makes it so that you know, it counts down. local hill = game.Workspace:WaitForChild("Hill") local PlayersTouching = hill:GetTouchingParts() for i, player in pairs(PlayersTouching) do if player.Parent:findFirstChild("Humanoid") then local Player = game.Players:GetPlayerFromCharacter(player.Parent) local Points = Player.Points Points.Value = Points.Value + 1 end end
IDK I JUST WROTE THIS OUT HOPEFULLY IT HELPS?
R$565,403 |
|
|
| Report Abuse |
|
|
|
| 03 Nov 2016 04:35 PM |
| Cytheur you are correct at what i am trying to do, thou it loots like gettouchingparts just tells you what parts are clipping with the scripts parent. |
|
|
| Report Abuse |
|
|
|
| 03 Nov 2016 04:39 PM |
| you should look into coroutines |
|
|
| Report Abuse |
|
|
|
| 03 Nov 2016 04:42 PM |
| that script doesn't seem to work though. |
|
|
| Report Abuse |
|
|
|
| 03 Nov 2016 04:45 PM |
| Coroutines look like what i'm looking for thanks. |
|
|
| Report Abuse |
|
|
|
| 03 Nov 2016 04:53 PM |
Try this:
PlayersInHill = {}
script.Parent.Touched:connect(function(Hit) if Hit.Parent:FindFirstChild("Humanoid") then if Hit.Parent:FindFirstChild("Humanoid").Health > 0 then Player = game.Players:GetPlayerFromCharacter(Hit.Parent) table.insert(PlayersInHill, Player) end end end)
script.Parent.TouchEnded:connect(function(Hit) if Hit.Parent:FindFirstChild("Humanoid") then if Hit.Parent:FindFirstChild("Humanoid").Health > 0 then Player = game.Players:GetPlayerFromCharacter(Hit.Parent) for i,v in pairs(PlayersInHill) do if v.Name == Player.Name then table.remove(PlayersInHill,i) end end end end end)
while wait(1) do if #PlayersInHill > 0 then for i,v in pairs(PlayersInHill) do v.leaderstats.Points.Value = v.leaderstats.Points.Value + 1 end end end
|
|
|
| Report Abuse |
|
|
|
| 03 Nov 2016 04:55 PM |
| Yes! that worked. thank you! |
|
|
| Report Abuse |
|
|
|
| 03 Nov 2016 04:58 PM |
for the sake of efficiency, don't put a "while wait()/true do" loop. always wrap it in a "spawn(function () end)" or a "coroutine.resume(coroutine.create(function () end))"
or however it works, id rather have an indented script on handy otherwise idk what im writing |
|
|
| Report Abuse |
|
|
Vortilis
|
  |
| Joined: 06 Jul 2014 |
| Total Posts: 14163 |
|
|
| 03 Nov 2016 05:00 PM |
please stop saying onTouch like it's a thing onTouch is just a common name its .Touched
|
|
|
| Report Abuse |
|
|
|
| 03 Nov 2016 05:03 PM |
its more logical and grammatically correct to say "on touched" if you feel triggered then too bad you can't edit forums |
|
|
| Report Abuse |
|
|
Vortilis
|
  |
| Joined: 06 Jul 2014 |
| Total Posts: 14163 |
|
|
| 03 Nov 2016 05:06 PM |
no it's better to say "if i make it a .Touched brick," saying "if I make it OnTouched" sounds stupid
|
|
|
| Report Abuse |
|
|
|
| 03 Nov 2016 05:07 PM |
I updated my script, It has some bugs in it:
PlayersInHill = {}
script.Parent.Touched:connect(function(Hit) if Hit.Parent:FindFirstChild("Humanoid") then if Hit.Parent:FindFirstChild("Humanoid").Health > 0 then Player = game.Players:GetPlayerFromCharacter(Hit.Parent) if #PlayersInHill == 0 then table.insert(PlayersInHill, Player) else for i,v in pairs(PlayersInHill) do if v.Name ~= Player.Name then table.insert(PlayersInHill, Player) end end end end end end)
script.Parent.TouchEnded:connect(function(Hit) if Hit.Parent:FindFirstChild("Humanoid") then Player = game.Players:GetPlayerFromCharacter(Hit.Parent) for i,v in pairs(PlayersInHill) do if v.Name == Player.Name then table.remove(PlayersInHill,i) end end end end)
while wait(1) do if #PlayersInHill > 0 then for i,v in pairs(PlayersInHill) do v.leaderstats.Points.Value = v.leaderstats.Points.Value + 1 end end end
|
|
|
| Report Abuse |
|
|
|
| 03 Nov 2016 05:10 PM |
| I have many ontouched bricks @Vortil |
|
|
| Report Abuse |
|
|
Vortilis
|
  |
| Joined: 06 Jul 2014 |
| Total Posts: 14163 |
|
|
| 03 Nov 2016 05:18 PM |
colbert you dont know how to code tho
|
|
|
| Report Abuse |
|
|
|
| 03 Nov 2016 05:18 PM |
yes I do know how to code *facepalm* |
|
|
| Report Abuse |
|
|
| |
|