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

Simple KO script not working?

Asked by 10 years ago
function tagHumanoid(humanoid)
local creator = Instance.new("StringValue",b) -- b is the name of the bullet
creator.Name = "creator" 
creator.Value = game.Players[script.Parent.Parent.Parent.Parent]
creator.Parent = humanoid
end

This code is in a part inside a gun.

What's wrong with this?

No output. It actually brakes the rest of the gun code after firing once. Let me know if you need more information. Thanks!

3 answers

Log in to vote
0
Answered by 10 years ago

Try this:

function tagHumanoid(humanoid)
 local creator = Instance.new("StringValue") 
local plrName = script.Parent.Parent.Parent.Parent.Name
local plr = game.Players:FindFirstChild(plrName)
 creator.Name = "creator" 
creator.Value = plr
creator.Parent = humanoid 
end

My changes: Line2: local creator = Instance.new("StringValue") I removed the "B", because it was parenting to B.

Inserted lines 3-4 local plrName = script.Parent.Parent.Parent.Parent.Name local plr = game.Players:FindFirstChild(plrName) Just a simple fix. I personally do not know if it actually makes a difference, but it looks a lot cleaner.

0
Didn't work :/ Zkiller11 0 — 10y
Ad
Log in to vote
0
Answered by 10 years ago
function tagHumanoid(humanoid) 
    local creator = Instance.new("StringValue",b) -- b is the name of the bullet 
    creator.Name = "creator" 
    creator.Value = game.Players[script.Parent.Parent.Parent.Parent] 
    creator.Parent = humanoid 
end

First of all, don't put all the code on one line like that. Not sure if you did that on accident, but it breaks the code..

Secondary, you are trying (Not successfully doing so) to set the value of a StringValue to a Player Object. This is not possible, the value has to be a string. You either have to use an object value, or set the value to the name of player.

Using an object value:

function tagHumanoid(humanoid) 
    local creator = Instance.new("ObjectValue") -- b is the name of the bullet 
    creator.Name = "creator" 
    creator.Value = game.Players[script.Parent.Parent.Parent.Parent] 
    creator.Parent = humanoid 
end

Using a string as value:

function tagHumanoid(humanoid) 
    local creator = Instance.new("StringValue") -- b is the name of the bullet 
    creator.Name = "creator" 
    creator.Value = script.Parent.Parent.Parent.Parent.Name
    creator.Parent = humanoid 
end

Btw, setting the parent of the value to b seems to be unnecessary, as it is parented somewhere else later on. You can change properties of objects even if they are not parented. Not having access to the full scripts I cannot tell if anything depends on these being parented to b, so you can always change it back in case something breaks.

0
http://pastebin.com/ag0ZsgH3 -- Full code Zkiller11 0 — 10y
Log in to vote
0
Answered by 10 years ago

Updated full code paste: http://pastebin.com/eMkUEqrQ

Sorry for the bump

Answer this question