Giving a certain tool to a certain person/even more

Hi devs, I have made Star Wars Force Powers tools and I need a script to give them to some people on join. This is the script I tried but it did not work and there was not anything in the output:

local ForceChoke = script.Parent["Force Choke Tool"]
local allowed = {250344137}

local function identify(thisPlayer)
	for _, current in pairs(allowed) do
		if current == thisPlayer.PlayerId then
			return true
		end
	end
end

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		if identify(player) then
			ForceChoke:Clone().Parent = player.Backpack
		end
	end)
end)

What’s the problem in this script? Thank you.

Just do this

game.Players.PlayerAdded:Connect(function(player)
    if player.UserId == [userId] then
        tool:Clone().Parent = player.Backpack
    end
end)

It is not working and the output says:

Workspace.Folder.Force Choke:4: Expected identifier when parsing expression, got ‘[’

Do not use [userId] that was an example you put the userId there for example mine

game.Players.PlayerAdded:Connect(function(player)
    if player.UserId == 1986453117 then
        tool:Clone().Parent = player.Backpack
    end
end)

Ok now there is not the output error but I do not have anything in my inventory

Did you add your userId where I put mine?

By going to your profile and taking the numbers from the link

Try this perhaps?

local ForceChoke = script.Parent["Force Choke Tool"]
local allowed = {250344137}

local function identify(thisPlayer)
	for _, current in pairs(allowed) do
		if current == thisPlayer.UserId then
			return true
		end
	end
end

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
        local Check = identify(player)
        print(Check)
		if Check then
			ForceChoke:Clone().Parent = player.Backpack
		end
	end)
end)
1 Like

Make sure you have the tool variable.

It worked thank you, but now the tool is not working, how can I fix it? Output error is:

Players.LuigiMinecraft03.Backpack.Force Choke Tool.Server:8: attempt to index nil with ‘HumanoidRootPart’

Show us the code. We can’t help without seeing the code

This is the script called Server

local module = require(script.Parent.Module)

script.Parent.Cool.Cooldown.OnServerEvent:Connect(function(plr, truefalse)
	script.Parent.Cool.Value = truefalse
end)

script.Parent.Cool.Fire.OnServerEvent:Connect(function(player, Enemy)
	Enemy.HumanoidRootPart.Anchored = true
	local SFX = script.Parent.Sounds.ForceCrush:Clone()
	SFX.Parent = player.Character.HumanoidRootPart
	SFX:Play()
	game.Debris:AddItem(SFX, 5)
	player.Character.Humanoid:LoadAnimation(script.Parent.Animations.Force):Play(0.2)
	game:GetService("TweenService"):Create(Enemy.HumanoidRootPart, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 0), {CFrame = Enemy.HumanoidRootPart.CFrame * CFrame.new(0,5,0)}):Play()
	spawn(function()
		wait(1)
		local anim = player.Character.Humanoid:LoadAnimation(script.Parent.Animations.ForceLoop)
		anim:Play()
		repeat wait()
			Enemy.HumanoidRootPart.CFrame = CFrame.new(Enemy.HumanoidRootPart.Position, player.Character.HumanoidRootPart.Position)
		until Enemy.Humanoid.Health <= 0
		anim:Stop()
	end)
	wait(2)
	Enemy.Humanoid:LoadAnimation(script.Parent.Animations.Victim):Play(0.3)
	local FX = script.Parent.Particles.Attachment.Attachment:Clone()
	FX.Parent = Enemy.HumanoidRootPart
	FX.Flare.Enabled = true
	local SFX2 = script.Parent.Sounds.Bones:Clone()
	SFX2.Parent = Enemy.HumanoidRootPart
	SFX2:Play()
	local SFX3 = script.Parent.Sounds.Activate:Clone()
	SFX3.Parent = Enemy.HumanoidRootPart
	SFX3:Play()
	local DisableGui = script.DisableGui:Clone()
	DisableGui.Parent = Enemy.HumanoidRootPart
	DisableGui.Disabled = false
	game.Debris:AddItem(SFX3, 9)
	game.Debris:AddItem(SFX2, 9)
	game.Debris:AddItem(FX, 9)
	wait(9)
	Enemy.Humanoid:TakeDamage(1498075041047501374050874805706713067813743701043)
	
end)

Script called DisableGui

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)

Script called Client

local player = game.Players.LocalPlayer
local tool = script.Parent
local module = require(script.Parent:WaitForChild("Module"))
local cool = script.Parent.Cool
local mouse = player:GetMouse()

tool.Activated:Connect(function()
	local Target = mouse.Target
		local Enemy = nil
		while true do
	       if Target == nil then
	           break
	       end
	       if Target == game.Workspace then
	           break
	       end
	       if Target.Parent:FindFirstChild("Humanoid") then
	           Enemy = Target.Parent
	           break
	       end
	       Target = Target.Parent
		end
	if cool.Value == false then
		module.CreateCooldown(tool, 0, tool.Name, script.Parent.Cool.Cooldown)
		cool.Fire:FireServer(Enemy)
	else
		return
	end
end)

Script called Module

local module = {}
		function module.CreateCooldown(tool, cooldown, originalname, event)
			spawn(function()
				if script.Parent.Cool.Value == true then return end
				tool.Name = cooldown
				event:FireServer(true)
				for i = 1,cooldown do
					wait(1)
					tool.Name = tool.Name - 1
				end
				tool.Name = originalname
				event:FireServer(false)
			end)
		end
		function module.CreateHitbox(Size, CoordinateFrame, player)
			local hitbox = Instance.new("Part", workspace)
			hitbox.CanCollide = false
			hitbox.Size = Size
			hitbox.CFrame = CoordinateFrame
			hitbox.Name = player.Name.. "HitBox"
			hitbox.Anchored = true
			hitbox.Transparency = 1
			for i,v in pairs(workspace:GetChildren()) do
				if v:IsA("Model") and v:FindFirstChild("Humanoid") and v:FindFirstChild("HumanoidRootPart") and v ~= player then
					if (hitbox.Position - v.HumanoidRootPart.Position).Magnitude <= 8 then
						local BV = Instance.new("BodyVelocity", v.HumanoidRootPart)
						BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
						BV.Velocity = player.HumanoidRootPart.CFrame.lookVector * 90
						v.Humanoid:LoadAnimation(script.Parent.Animations.Victim):Play(0.2)
						v.HumanoidRootPart.CFrame = CFrame.new(v.HumanoidRootPart.Position, player.HumanoidRootPart.Position) 
						v.Humanoid.PlatformStand = true
						spawn(function()
							wait(3)
							v.Humanoid.PlatformStand = false
						end)
						game.Debris:AddItem(BV, 0.3)
					end
				end
			end
			game.Debris:AddItem(hitbox, 2)
		end
return module

My friend gave me his tools so I did not make these scripts

Looks like Target is being returned as a nil value from the server side, it might also be because you need to reference only the Target’s HumanoidRootPart? Not sure

Add print statements from both the client & server side