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

How to make an object appear only when a value is a certain amount?

Asked by
soutpansa 120
7 years ago

I have an NPC that drops a big glowing chest when it dies. But the problem is that the NPC will only fight other players if it is touched by them first, which means that players can just use ranged attacks to kill the NPC without a fight. When the NPC is touched, a value inside of it named "Target" , gets the value changed to the name of the player that touched it. For example, if Player1 touches the NPC, the value is then changed to Player1. Simple. How do I make this script only drop the chest when the Target value actually has something assigned to it?

function onDied()


    for i =1,script.GoldCount.Value do

        local xp = Instance.new("Part")

        xp.Parent = game.Workspace

        xp.Position = script.Parent.Parent.Torso.Position + Vector3.new(math.random(1,4),3,math.random(1,4))

        xp.Shape = 1

        xp.BrickColor = BrickColor.new("Bright yellow")
        local z = Instance.new("SpecialMesh", xp)
        z.MeshType = "Sphere"
        z.MeshId = "http://www.roblox.com/asset/?id=23723701"
        z.Scale = Vector3.new(3, 3, 3)
        xp.Reflectance = 0.3
        xp.Transparency = 0
        local zz = Instance.new("PointLight")
        zz.Range = 60
        zz.Brightness = 60
        zz.Color = Color3.new(255,255,255)
        zz.Parent = xp

        xp.Size = Vector3.new(3, 3, 3)



        local clone = script.Increase:Clone()

        clone.Disabled = false

        clone.Parent = xp

    end


end





script.Parent.Died:connect(onDied)

2 answers

Log in to vote
0
Answered by 7 years ago

You could put something like this:

function onDied()
    if Target = not nil then -- assuming that Target is the variable that has the player name
        -- all of your code that is inside the function onDied
    end
end

Hope this works! I couldn't test it yet because I don't have anything to test it on.

Ad
Log in to vote
0
Answered by 7 years ago

Hmm, what you could do is use a check function, for example,


if YourID.Value>50 then YourID.Value = 0 -- The rest of your script goes here end

What that would do is it would check if if a certain value inside the playerdata(which I assume you have made) is over a certain number point it would make all of that script.

However, you would need a script that does add to that ID say roughly, 5 or so each time you get a kill.

DISCLAIMER: I have not tested this script myself, and this is only part of a much larger script. You would have to make a much larger script that would get a player from hit and etc that would add values and etc.

I hope I helped! If you have any questions feel free to ask me!

Answer this question