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

Having some problems with making a Shared XP/Gold Setup?

Attack Script for the Npc:

Texture.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild('Humanoid') then
		local char = hit.Parent

if char.Shared:FindFirstChild("Check1") then
		-- Checking if player doesn't have the Value
		else
		local Int = Instance.new('BoolValue',char.Shared)
		Int.Name = "Check1"
		Int.Value = true
		end

Npc Died Script:


for _,p in pairs(game.Players:GetPlayers()) do 
if p.Character.Shared.Check1.Value == true then
print (p.Name.." Gain the loot")

p.Character.Shared.Check1:Remove()
end
end

I'm not sure if this would give everyone in the game the same loot or would it just give the player that has "Check1" in there Character the Loot and not everyone else. Is there a better way of doing this?

3 comments

0

You're using Remove() :c

0

Still new to half of this stuff, Remove() not good to use or something? There's only 2 I know of and that's Remove() / Destroy()

0

Yeah, don't use Remove() use Destroy() or use game.Debris:AddItem(p.Character.Shared.Check1, wait())

1 answer

Your problem is that the Check1 value may not reside in the current player you're checking on line 2 of the Died script. Check if 'Check1' exists prior to indexing the value.

Attack;

Texture.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild('Humanoid') then
		local shared = hit.Parent.Shared
		if not shared:FindFirstChild("Check1") then
			local Int = Instance.new("BoolValue",shared)
			Int.Name = "Check1"
			Int.Value = true
		end
	end
end

Died;

for _,p in pairs(game.Players:GetPlayers()) do 
	local val = p.Character.Sharacter:FindFirstChild("Check1")
	if val then
		if val.Value then
			print (p.Name.." gained the loot")
			val:Destroy() --remove is deprecated
		end
	end
end

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