|
| 20 Aug 2016 04:24 PM |
Trying to make a seat give you a leaderstat depending on how long you sit in it
I tried a while true do loop which didn't work and I scrapped that, But now I'm trying a for loop. Here's the code :
function onTouched(hit) local h = hit.Parent:findFirstChild("Humanoid") if h and h.Sit == true then for _, player in ipairs(game.Players:GetPlayers()) do if player:FindFirstChild("leaderstats") then player.leaderstats.Intelligence.Value = player.leaderstats.Intelligence.Value - 1 end end end end
|
|
|
| Report Abuse |
|
|
|
| 20 Aug 2016 04:24 PM |
| Also, how do you make a leaderstat unable to go over a certain number..? |
|
|
| Report Abuse |
|
|
|
| 20 Aug 2016 04:27 PM |
you can use an intconstrainedvalue to make a leaderstat unable to go over a certain number
http://wiki.roblox.com/index.php?title=API:Class/IntConstrainedValue |
|
|
| Report Abuse |
|
|
|
| 20 Aug 2016 04:32 PM |
| Dude, that's perfect, thanks! I never knew what IntConstrainedValue's did |
|
|
| Report Abuse |
|
|
| |
|
| |
|
| |
|
| |
|
|
| 20 Aug 2016 05:26 PM |
| last boomp then thread die :( |
|
|
| Report Abuse |
|
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
|
| 20 Aug 2016 05:28 PM |
function onTouched(hit) local h = hit.Parent:findFirstChild("Humanoid") while h and h.Sit == true do if game.Players[Humanoid.Parent.Name].leaderstats then game.Players[Humanoid.Parent.Name].leaderstats.Intelligence.Value = game.Players[Humanoid.Parent.Name].leaderstats.Intelligence.Value - 1 wait(1) -- seconds it takes to subtract one intellegence end end end
try that :) |
|
|
| Report Abuse |
|
|
| |
|
|
| 20 Aug 2016 05:36 PM |
Says unknown global humanoid under the
if game.Players[Humanoid.Parent.Name].leaderstats then
part
Also I made a local variable for finding the humanoid already Won't local variables work in an if-then statement..?
Sorry for my newbieness I'm new to this |
|
|
| Report Abuse |
|
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
|
| 20 Aug 2016 05:37 PM |
| yeah sorry i wasn't really paying attention, just change Humanoid to h in all appearances |
|
|
| Report Abuse |
|
|
| |
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
|
| 20 Aug 2016 05:42 PM |
08-20-2016 03:28 PM function onTouched(hit) local h = hit.Parent:findFirstChild("Humanoid") while h and h.Sit == true do if game.Players[h.Parent.Name].leaderstats then game.Players[h.Parent.Name].leaderstats.Intelligence.Value = game.Players[h.Parent.Name].leaderstats.Intelligence.Value - 1 wait(1) -- seconds it takes to subtract one intellegence end end end
try that :)
|
|
|
| Report Abuse |
|
|
|
| 20 Aug 2016 05:51 PM |
| yah I changed Humanoid to h whenever I saw it in the script it still doesn't work |
|
|
| Report Abuse |
|
|
|
| 20 Aug 2016 06:24 PM |
| noooo they went offline halp |
|
|
| Report Abuse |
|
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
|
| 20 Aug 2016 06:28 PM |
what does it print if it doesn't print anything check if it is actually a leaderstat |
|
|
| Report Abuse |
|
|
|
| 20 Aug 2016 06:30 PM |
It doesn't print anything idk
The Value is changed to IntConstrainedValue just like how @aggressivecatch recommended to me |
|
|
| Report Abuse |
|
|
|
| 20 Aug 2016 06:38 PM |
| ughhhh i feel like this is so simple but i'm so dumb for not knowing how to do this |
|
|
| Report Abuse |
|
|
|
| 20 Aug 2016 08:46 PM |
@Wowgnomes
Nevermind no more help needed,
it was because I didn't call the function on touch |
|
|
| Report Abuse |
|
|