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

Cant make pvp system work normally, what to do?

Asked by 5 years ago
01wait(1)
02local player = script.Parent.Parent.Parent.Name
03 
04script.Parent:WaitForChild("Blade").Touched:connect(function(p)
05    local playername = p.Parent.Name
06    print(playername)
07-- if playername.Parent == (i dont know what to place here, there must be ONLY player name that got hitten but if i make this, it also can give the error cause there is accessories and morphes) then
08 
09    local plr = game.Players:WaitForChild(playername)
10    local pvp = plr:WaitForChild("Backpack"):FindFirstChild("PVP").Value
11    local pvpl = game.Players:FindFirstChild(player).Backpack.PVP
12    local block = game.Players:FindFirstChild(playername):WaitForChild("Backpack"):WaitForChild("Block")
13    local CanDamage = game.Players:FindFirstChild(playername):WaitForChild("Backpack"):WaitForChild("CanDamage")
14 
15    if pvp.Value == true and block.Value == false and pvpl.Value == true then
View all 24 lines...

the script must identify the player name to make the others parts work on the --, but it gives error cause it cant find the player name cause of others parts like accessories or morph.

1 answer

Log in to vote
0
Answered by 5 years ago

If it can't find the player because of a "nil value" or something, use LocalPlayer
LocalPlayer is the same thing as your event's argument "p"

01wait(1)
02local player = script.Parent.Parent.Parent.Name -- I don't know what this variable is for. So I left it out.
03 
04script.Parent:WaitForChild("Blade").Touched:connect(function(p)
05    local playername = game.Players.LocalPlayer.Name
06    print(playername)
07    local pvp = playername:WaitForChild("Backpack"):FindFirstChild("PVP")
08    local block = game.Players:FindFirstChild(playername):WaitForChild("Backpack"):WaitForChild("Block")
09    local CanDamage = game.Players:FindFirstChild(playername):WaitForChild("Backpack"):WaitForChild("CanDamage")
10 
11    if pvp.Value == true and block.Value == false then
12    if CanDamage.Value == true then
13 
14    script.Parent.CanDamage.Value = false
15 
16    workspace[playername].Humanoid:TakeDamage(math.random(10,30))
17    end
18    end
19    end
20end)
0
LocalPlayer works with Local script which my script isnt digameschannel 44 — 5y
0
Use a RemoteFunction to transfer the value of a LocalPlayer to a script. You can search up "RemoteFunction" on google and get tons of results. ViviTheLuaKing 103 — 5y
0
No, i need to get the name of ANOTHER user if he touch my blade, so i can access his backpack and check if his pvp enabled, but i cant since there is other models morphs and accessories digameschannel 44 — 5y
Ad

Answer this question