Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Cant make pvp system work normally, what to do?

wait(1)
local player = script.Parent.Parent.Parent.Name

script.Parent:WaitForChild("Blade").Touched:connect(function(p)
	local playername = p.Parent.Name
	print(playername)
-- 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

	local plr = game.Players:WaitForChild(playername)
	local pvp = plr:WaitForChild("Backpack"):FindFirstChild("PVP").Value
	local pvpl = game.Players:FindFirstChild(player).Backpack.PVP
	local block = game.Players:FindFirstChild(playername):WaitForChild("Backpack"):WaitForChild("Block")
	local CanDamage = game.Players:FindFirstChild(playername):WaitForChild("Backpack"):WaitForChild("CanDamage")
	
	if pvp.Value == true and block.Value == false and pvpl.Value == true then
	if CanDamage.Value == true then

	script.Parent.CanDamage.Value = false

	p.Parent.Humanoid:TakeDamage(math.random(10,30))
	end
	end
	end
end)

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

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"

wait(1)
local player = script.Parent.Parent.Parent.Name -- I don't know what this variable is for. So I left it out.

script.Parent:WaitForChild("Blade").Touched:connect(function(p)
    local playername = game.Players.LocalPlayer.Name
    print(playername)
    local pvp = playername:WaitForChild("Backpack"):FindFirstChild("PVP")
    local block = game.Players:FindFirstChild(playername):WaitForChild("Backpack"):WaitForChild("Block")
    local CanDamage = game.Players:FindFirstChild(playername):WaitForChild("Backpack"):WaitForChild("CanDamage")

    if pvp.Value == true and block.Value == false then
    if CanDamage.Value == true then

    script.Parent.CanDamage.Value = false

    workspace[playername].Humanoid:TakeDamage(math.random(10,30))
    end
    end
    end
end)

3 comments

0

LocalPlayer works with Local script which my script isnt

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.

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

This discussion is preserved as it was. New answers, comments, and votes are closed.