Medkit script not working

No. It’s a gamepass. I’m using this for my gamepass script:

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function()
		if Player.Name == 'Little_Joes' then
			for _, v in pairs(game.ReplicatedStorage.GamepassTools:GetChildren()) do
				v:Clone().Parent = Player.Backpack
			end
		end
		for i, gamepass in pairs(game.ReplicatedStorage.GamepassTools:GetChildren()) do
			if MPS:UserOwnsGamePassAsync(Player.UserId, gamepass.Name) then
				local ID = gamepass.Name
				local Cloned = game.ReplicatedStorage.GamepassTools[ID]:Clone()
				Cloned.Parent = Player.Backpack
			end
		end
	end)
end)

The item gets cloned from ReplicatedStorage

No. It’s a gamepass. I’m using this for my gamepass script:

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function()
		if Player.Name == 'Little_Joes' then
			for _, v in pairs(game.ReplicatedStorage.GamepassTools:GetChildren()) do
				v:Clone().Parent = Player.Backpack
			end
		end
		for i, gamepass in pairs(game.ReplicatedStorage.GamepassTools:GetChildren()) do
			if MPS:UserOwnsGamePassAsync(Player.UserId, gamepass.Name) then
				local ID = gamepass.Name
				local Cloned = game.ReplicatedStorage.GamepassTools[ID]:Clone()
				Cloned.Parent = Player.Backpack
			end
		end
	end)
end)

The item gets cloned from ReplicatedStorage and this script is in Workspace.

Well this should be an easy fix then:

  • Disable the server script inside the tool in Studio
  • In your script: After cloning and parenting the tool to the player’s backpack, re-enable the script

It should work, and also you should include details like that for any future posts, makes it more understandable for everyone.

Oh you mean I can just do this?

Not sure what you mean, but here’s an example:

	Player.CharacterAdded:Connect(function()
		if Player.Name == 'Little_Joes' then
			for _, v in pairs(game.ReplicatedStorage.GamepassTools:GetChildren()) do
				--The new stuff:
				local clonedTool = v:Clone().Parent
				clonedTool.Parent = Player.Backpack
				clonedTool:WaitForChild("Script").Disabled = false
				--^If your other tools don't follow the same format as my medkit in the workspace,
				--then feel free to add an "If" statement checking it's name or something
			end
		end
	end)

Whilst disabling the tool’s server script in Studio, so it doesn’t set the variables unaccordingly to the ReplicatedStorage

So I can just use my old scripts?

Yep! With a little bit of modification, (I assume you have some basic scripting knowledge because you already have a decent start) you can make it work, just like in the example I posted.

Just make sure to check if all your tools follow the same workspace layout as the medkit, if not, rename the medkit and simply whitelist it with an “If” statement checking the cloned tool’s name so you don’t error.

But could I use this? Would this work if I just added in that script you told me to?

Put the medkit tool into the replicated storage, and follow the example I posted:

The example code is just a modified version of the code you already have, apply the changes I made “–The new stuff” to your other existing block of code as well (the one that checks gamepasses).

So i can just do this?

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function()
		if Player.Name == 'Little_Joes' then
			for _, v in pairs(game.ReplicatedStorage.GamepassTools:GetChildren()) do
				v:Clone().Parent = Player.Backpack
			end
		end
		for i, gamepass in pairs(game.ReplicatedStorage.GamepassTools:GetChildren()) do
			if MPS:UserOwnsGamePassAsync(Player.UserId, gamepass.Name) then
				local clonedTool = gamepass:Clone().Parent
				clonedTool.Parent = Player.Backpack
				if clonedTool:FindFirstChild('Script') then
					clonedTool:WaitForChild("Script").Disabled = false
				end
			end
		end
	end)
end)

Pretty much, I would also check for a script in the other block of code; the one cloning tools for yourself. You can also use FindFirstChildOfClass(“Script”) in the case where your script is not named “Script”.

That didn’t work, I’ve got a server script in my tool, that has this in it:

Medkit = script.Parent

--// Code
script.Parent.Activated:Connect(function()
	local char = script.Parent.Parent
	local plr = game.Players:GetPlayerFromCharacter(char)
	if plr then
		local h = plr.Character.Humanoid
		for i = h.Health, h.MaxHealth, 1.5 do
			if h.Health > 0 and h.Health < h.MaxHealth then
				h.Health = i
				wait(1)
			end
		end
		if h.Health < h.MaxHealth then
			Medkit:Destroy()
	end
	else 
		print "NO PLAYER FOUND"
	end
end)

and I have this script in Workspace:

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function()
		if Player.Name == 'Little_Joes' then
			for _, v in pairs(game.ReplicatedStorage.GamepassTools:GetChildren()) do
				local clonedTool = v:Clone()
				clonedTool.Parent = Player.Backpack
				if clonedTool:FindFirstChild('Script') then
					clonedTool:WaitForChild("Script").Disabled = false
				end
			end
		end
		for i, gamepass in pairs(game.ReplicatedStorage.GamepassTools:GetChildren()) do
			if MPS:UserOwnsGamePassAsync(Player.UserId, gamepass.Name) then
				local clonedTool = gamepass:Clone()
				clonedTool.Parent = Player.Backpack
				if clonedTool:FindFirstChild('Script') then
					clonedTool:WaitForChild("Script").Disabled = false
				end
			end
		end
	end)
end)

It doesn’t give me any errors. I used the console to set my health to 30. I clicked the medkit and nothing happened.

Did you use the local and server script I posted? Those worked perfectly fine when I tested them in Studio.

Thanks a lot. It worked!!!

1 Like