Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Trying to string names together in a parameter but I can't figure it out? I accept answers!

Asked by
M9F 94
4 years ago

I'm trying to make it where multiple peoples name can be stored inside the parameter in the variable allowedPlayers

01local object = script.Parent
02local fireObject = game.ReplicatedStorage.speedFire
03local player = workspace
04local allowedPlayers = ("M9F", "") ---- this is what I need help with
05local debounce = false
06 
07local function giveSpeed(hit)
08    if debounce == false then
09        debounce = true
10        if hit.Parent:FindFirstChild("Humanoid")then
11            if hit.Parent.Name == allowedPlayers then
12                hit.Parent.Humanoid.WalkSpeed = 50
13                hit.Parent.Humanoid.JumpPower = 75
14                if not hit.Parent.Head:FindFirstChild("speedFire")then
15                    local clonedFire = fireObject:Clone()
View all 23 lines...
0
ok i know how to do this hold on let me write this out AlexanderYar 788 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

Alright, if you dont know, any string array can have as many strings in it as you want, as long as you specify which number it is. for example, you cannot put in a string = the string array because it doesnt work that way, you have to specify which string in the string array you want to ad or change, like stringarray[2] or the next one after that is stringarray[3], the lowest is 0, so you may be wondering "how do i insert player names into different string arrays" well fun quick story, when i was new to scripting, i used math.random but that was stupid and the sloppiest idea ever, anyway, to do this, change the number everytime and be PREDICTABLE WHILE YOU DO IT, math .random isnt predictable and two numbers could be the same,

the quick answer? Just increment a value everytime a player is added so the numebr is always different and is 1 higher than the last. so your code should be like this (i added a value called num):

01local object = script.Parent
02local fireObject = game.ReplicatedStorage.speedFire
03local player = workspace
04local allowedPlayers = ("M9F", "") ---- this is what I need help with
05local debounce = false
06local num = 0
07 
08local function giveSpeed(hit)
09    if debounce == false then
10        debounce = true
11        if hit.Parent:FindFirstChild("Humanoid")then
12            if hit.Parent.Name == allowedPlayers[num] then
13num += 1 --adds 1 , same as num = num + 1
14                hit.Parent.Humanoid.WalkSpeed = 50
15                hit.Parent.Humanoid.JumpPower = 75
View all 25 lines...

hope this helps :3

oh hold on i jsut realised i misunderstood the qustion, ok i understand now, lemme answer it correctly this time heheh sorry.

So your trying to test all of the player names in the string array to see if they math the player being tested. simple, make a pairs loop like this.

01failures = 0
02 
03for _,i in pairs(allowedPlayers) do
04 
05    if not i == hit.Parent.Name then--so this means if the player name does NOT match whats in the string being testing in the string array
06 
07        failures += 1 --adds one
08 
09    end
10 
11end
12 
13--any code after the loop will run when the loop finished, which means this code below will run once all strings in the array are tested
14 
15if failures == #allowedPlayers then--# means number or amount, so #allowedPlayers means the amount of strings in that array, so if all the strigns failed, then below code with execute
16 
17--code you want
18 
19end
0
sorry it took so long, my internet connection cut out so i had to wait for it to get back on, also just add elseif to run code when not all the strings in the string array are failures, which means at least one of them is the name of the player that your testing. AlexanderYar 788 — 4y
Ad

Answer this question