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

My ores are not adding money to the leaderboard?

plr = game.Players.LocalPlayer
worth = game.Players.plr.leaderstats.Money.Value 
function destroy(hit) --'hit' parameter is now the part that touched!
    if hit.Name == "drop" then --Check the hit's name.
		worth = worth+10
        hit:Destroy()
    end
end
 
--workspace.drop.Touched:connect(destroy)
script.Parent.Touched:connect(destroy)

Im not sure why this does not add 10 when it hits the furnace

5 answers

✓ Accepted answer

When you set a variable to a ValueObject's Value property, that variable becomes equivalent to what the Value was when the script executed that line of code.

By changing the variable, you are simply changing the variable. The ValueObject's value is not affected.

You need to reference the object from the variable, and index the property to set it.


Now, secondly, you are getting the Player incorrectly. Since this is a server script you cannot use game.Players.LocalPlayer. You need to get the player some other way. That way is up to you. Preferably by an 'owner' StringValue to the tycoon.

local plr --This is the player.
local worth = plr:WaitForChild("leaderstats"):WaitForChild("Money")

function destroy(hit)
	if hit.Name == "drop" then
		worth.Value = worth.Value + 10
		hit:Destroy()
	end
end

script.Parent.Touched:connect(destroy)

I'm just gonna fix this, upvote and accept answer if worked

In a local script;

local player = game.Players.LocalPlayer
local Value = 10 -- the value of the ore
local curreny = player:WaitForChild("leaderstats").Money.Value
local Furnace = script.Parent --The furnace
local Cashed = false --make debounce so the player doesn't get a lot of 10 money

Furnace.Touched:connect(function(Hit)
	wait() --Dunno why
	if Hit.Parent.Name == "Drop" then
		Cashed = true
		wait() -- Dunno why
		currency = currency + Value
		Hit.Parent:Destroy()
		wait() -- Dunno why
		Cashed = false
		if Cashed then return end -- We don't want the player to get too much money
	end
end)

Try, comment, ask and explain.

1 comment

0

Explain the reason behind your answer plz. Thanx. c;

Don't use a LocalScript!

LocalScripts don't work in workspace unless they're in a player character. Also, if FE was enabled, the local scripts would only affect the value locally, which you obviously don't want!

The next problem is you need to get the player. But which player? That's something you need to figure out, but I'll provide an example. By touching the ownerBrick, you become the owner of this tycoon.

local owner

local debounce = false
local function destroy(hit)
	if owner and not debounce and hit.Name == "drop" then
		debounce = true
		local worth = owner.leaderstats.Money
		worth.Value = worth.Value+10
		hit:Destroy()
		wait(.5)
		debounce = false
	end
end
script.Parent.Touched:Connect(destroy)

local ownerBrick = script.Parent.Parent:WaitForChild("OwnerBrick")
ownerBrick.Touched:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if((plr)and(not owner))then
		owner = plr
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	if(plr ==  owner)then
		owner = nil
	end
end)

This is the solution. You need to have the .value after the 'worth' value. Then it will work.

local plr --This is the player.
local worth = plr:WaitForChild("leaderstats"):WaitForChild("Money")

function destroy(hit)
    if hit.Name == "drop" then
        worth.Value = worth.Value + 10
        hit:Destroy()
    end
end
 
script.Parent.Touched:connect(destroy)

ok so there are many errors but idk if i can completely solve ur error. i will make a few changes though.

[UPDATE!]: now that i know ur problem.. ill try again.

SCRIPT.

in that item(part) make a group then add a humanoid inside the group. then add this script inside the part.

it should look like this.

GROUP>(Humanoid, OrePart).OrePart>Script>(inside the script below)

function onTouched(part)
	local ore = script.Parent
	local h = part.Parent:findFirstChild("Humanoid")
	if (h~=nil) then
		local thisplr = game.Players:findFirstChild(h.Parent.Name)
		if (thisplr~=nil) then
			local stats = thisplr:findFirstChild("leaderstats")
			if (stats~=nil) then
				local score = stats:findFirstChild("Money")-- change this to what the thing is like Money or Points
				if (score~=nil) then
					score.Value = score.Value + 10 -- change this to the number of cash they get
				end
				ore:Destroy()
			end
		end
	end

end

script.Parent.Touched:connect(onTouched)

MY FINAL ANSWER, HOPE IT WORKS.

5 comments

0

If you're unsure of how to actually fix, don't bother answering:P

0

i love to try, it's how i learn.

0

Great for you, unfortunately for others it's not as enlightening - just an inaccurate solution.

0

if it's a right answer then i feel more happy, and i learn more and i progress that way

0

Explain the reason behind your answer plz. Thanx. c;

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