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

Why does this exp and gold giving script in my enemy in workspace not work?

There are no errors in the out put and I dont know why it does not work. I found it on youtube, heres the script

local hum = script.Parent.Humanoid
hum.Died:Connect(function()
	local tag = hum:FindFirstChild("creator")
	if tag ~= nil then
		if tag.Value ~= nil then
			local lstats = tag.Value.leaderstats
			lstats.Gold.Value = lstats.Gold.Value +10
			lstats.Experience.Value = lstats.Experience.Value +3
		end
	end
end)

1 answer

Not sure but I think you have to do this way differently. I would do something like

local hum = script.Parent.Humanoid
hum.Died:Connect(function(player)
	player.leaderstats.Gold.Value = player.leaderstats.Gold.Value + 10
	player.leaderstats.Experience.Value = player.leaderstats.Experience.Value + 3
end)

But make sure the leaderstats actually exists. Something similar to that. If it doesn't work I think you need to add some script to the weapon to find the player who killed the NCP. If it's a player, not an NCP then try putting the script in startercharacterscripts. Otherwise, you need to add some code to the weapon. Edit: Use this kind of leaderstats

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("CashSaveSystem")

game.Players.PlayerAdded:connect(function(player)
	local leader = Instance.new("Folder",player)
	leader.Name = "leaderstats"
	local Cash = Instance.new("IntValue",leader)
	Cash.Name = "Cash"
	Cash.Value = ds:GetAsync(player.UserId) or 0
	ds:SetAsync(player.UserId, Cash.Value)
	Cash.Changed:connect(function()
		ds:SetAsync(player.UserId, Cash.Value)
	end)
end)

7 comments

0

okay, i will try this. I used creator because its said to specify who killed someone

0

Doesnt work, sorry mate. "Attempted to index nil with leaderstats" Even though i have stats loaded.

0

Make sure all the lines are correct and try making some script in the weapon. Also make sure your leaderstats exists and is named what is there.

0

Try using this kind of leaderstats script

0

Try using this kind of leaderstats script

0

@cancle5 I have style of script like that already. I need to save four leaderstats which I already am doing, I don’t think yours would change anything.

0

@cancle5 I have style of script like that already. I need to save four leaderstats which I already am doing, I don’t think yours would change anything.

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