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

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

Asked by
Kuzx 22
7 years ago

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?

0
You're using Remove() :c OldPalHappy 1477 — 7y
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() Kuzx 22 — 7y
0
Yeah, don't use Remove() use Destroy() or use game.Debris:AddItem(p.Character.Shared.Check1, wait()) AstrealDev 728 — 7y

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago

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
Ad

Answer this question