(I know this has been the like 5th post in 2 days on this category but i promise this is the last since its the final thing in the update for my game)
So recently ive been working on a script that makes npcs/players give money when killed
When ever i find a tutorial it isnt working
I make sure it checks the value in the humanoid which determines who killed the player (For now i change the value in studio)
I understand they use the default roblox sword which adds a value into the player but whenever i change the value myself it dosnt work
It need to work without the sword or my fighting game is done for ;-;
So im asking if you guys have any ideas on how to do this
(Im not asking for an entire script,just ways to do it)
Also the money in my game is called Credits
And the creator value has been inserted into all the Play-Able characters humanoids
Hope you can help
-Neptune
1 Like
Just make it when the humanoid gets hit my a sword object and dies it gives them money/
1 Like
Not to be rude but its not that simple
It will be hard for us to help you if we don’t have a script or an idea on how your system works. If you have any code please share it or general idea on how you want it to work.
Edit: Are you asking how you track the Humanoid health in studio and figure out who kills the NPC humanoid?
1 Like
Also if the hit.parent is an NPC
1 Like
Simple in my brain tbh. Cannot help you without a script as @NotMyAccountWasTaken said.
1 Like
Alright ive got a small idea
My plan is to fire an event from the script in an npc and also send the money and person who killed the npc then making the server search for the player sent by the event then adding the money sent in the event
1 Like
Sorry i cant provide the script since i deleted them
And no not really i have the ideas how to do that but when executed they dont work
Sorry if im being confusing
Alright heres the npc script part of me thinks the code they used in these tutorials is kinda weird
Like i dont think my players leaderstats are in the creator value 0-0
local Humanoid = script.Parent.Humanoid
function GiveMoney()
local tag = Humanoid:findFirstChild("creator")
if tag ~= nil then
if tag.Value ~= nil then
local Leaderstats = tag.Value:findFirstChild("leaderstats")
if Leaderstats ~= nil then
Leaderstats.Credits.Value = Leaderstats.Credits.Value + 50 --Change Money to the stat that is increased.
end
end
end
end
Humanoid.Died:connect(GiveMoney)
Alright its coming up with this error
Workspace.Normal Dummy .money kill:6: attempt to call a nil value
local Humanoid = script.Parent:FindFirstChild("Humanoid")
function GiveMoney()
local tag = Humanoid:FindFirstChild("creator")
if tag ~= nil then
if tag.Value ~= nil then
local Leaderstats = tag.Value:FindFirstChild("leaderstats")
if Leaderstats ~= nil then
Leaderstats.Credits.Value = Leaderstats.Credits.Value + 50
end
end
end
end
Humanoid.Died:Connect(GiveMoney)
Try this as you had some syntax errors in your code.
1 Like
Ok ive had to come studio for a bit but ill try that tomorrow
By the way thanks for helping with this it appears to be simple but me being well ye Stuipid
find it hard
This is also gonna be really important and thanks since if no one commented the game would be in a lot of trouble
Nope these scripts are weird now
No error popping up but its not working : /
Try implementing print()
statements?
local Humanoid = script.Parent:FindFirstChild("Humanoid")
function GiveMoney()
print("Ow")
local tag = Humanoid:FindFirstChild("creator")
if tag ~= nil then
print("Found a Tag Object")
if tag.Value ~= nil then
print("Found a Value inside the Tag Object")
local Leaderstats = tag.Value:FindFirstChild("leaderstats")
if Leaderstats ~= nil then
print("Giving stats")
Leaderstats.Credits.Value = Leaderstats.Credits.Value + 50
end
end
end
end
Humanoid.Died:Connect(GiveMoney)
1 Like
Same error as before
Workspace.Normal Dummy .money kill:9: attempt to call a nil value
I think it may something to do with me changing the value in explorer (In the server option by the way) instead of changing it with a script
The tag.Value
should be a Player object if I recall correctly, and it looks like it stops after it attempts to find the leaderstats
object
I don’t think changing the value in the Explorer could be anything to do with it
Are you sure that this script is parented to the NPC’s/Player’s Model?
Im sure the script is parented to the npc and w
Im not very good at this part of scripting and dont really understand that
Can you explain it a bit?
Usually whenever a ObjectValue
is created onto the Target and it dies, it checks for all of the sanity checks using if tag ~= nil
/if tag.Value ~= nil
and such
Just try this script, see what outputs back (Print statements only)
local Humanoid = script.Parent:FindFirstChild("Humanoid")
function GiveMoney()
print("Ow")
local tag = Humanoid:FindFirstChild("creator")
print(tag)
if tag ~= nil then
print("Found a Tag Object")
if tag.Value ~= nil then
print(tag.Value)
print("Found a Value inside the Tag Object")
local Leaderstats = tag.Value:WaitForChild("leaderstats", 3)
print(Leaderstats)
if Leaderstats ~= nil then
print("Giving stats")
Leaderstats.Credits.Value = Leaderstats.Credits.Value + 50
end
end
end
end
Humanoid.Died:Connect(GiveMoney)
1 Like
Ok
It printed
Ow
creator
found a tag object
found a value inside the tag object
Did Leaderstats
print nil at all?
1 Like
Nope didnt get printed at all this is confusing