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

How would i add a numbervalue that is inside a part ontouched to a numbervalue in localplayer?

I am currently trying to make a sandbox tycoon and I put a numbervalue inside of the money (money is like the ore in Miners Haven) that is the value of the money, but I cannot find a way to make it where when it touches a certain part it gets the value from the numbervalue inside of the money and adds it to the Cash value inside of localplayer.leaderstats Please help! This is what I have tried

local repStorage = game:GetService("ReplicatedStorage")
	function onTouched(hit)	
	if hit.Name == "Cash" then
	game.Players.LocalPlayer.leaderstats.Cash.value = game.Players.LocalPlayer.leaderstats.Cash.value + hit.Value.Value
	hit:remove()
	end
	end
script.Parent.Touched:connect(onTouched)

I am aware that localplayer does not work inside of server scripts, but this is an example of what i need to happen

6 comments

0

Can you post the code you've tried?

0

I have tried with remote events but i suck with them, how do i post script here in a readable way?

0

When you ask or edit a question, there’s a blue circle with text that says “Lua” in it. Click it and copy paste your code between the squiggly lines that appear.

0

I have tried with remote events but i do not have the script i tried because when it didnt work i then tried what is above

0

bump

0

Local Scripts don't work in workspace.

1 answer

I don't think remote events are necessary when you want to change a value in the leaderstats. Also I re-wrote your script since it was really confusing to me. Here's the script :

EDIT: I edited the script. Also you'll have to find a way to set the "plrname" to the owner of the tycoon. Maybe when the player touches a part or something it sets a value? Idk. There's multiple ways to do this.

local repStorage = game:GetService("ReplicatedStorage")
local plrname = 'InsertNameHere' --Player name
local plr = game.Players(plrname) -- Finds player

function onTouched(hit) 
    if hit.Name == 'Cash' then
	plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value + script.Parent.Cash.Value --Gives money based on value in money
	script.Parent:Destroy()
	end
end

script.Parent.Touched:Connect(onTouched) 

22 comments

0

I am so confused, is there a way to send a screenshot? because i would need to show you where the money is and what is being touched

0

I use Gyazo to show screenshots to people. So...yeah.

0

could i give you access to my game in studio and you can look at what i need help with, it is really hard to expain,but i will try to explain. Anyways there are 4 tycoons and in each there is a model called itemHolder, when you place something it goes into itemholder. The thing that is being touched by the money is in itemholder.RustyVault.Conveyor, the ontouched script is in here. The money is

0

is in itemholder.RustyPrinter.SpawnLocation, it has a numbervalue inside of the money and it has the value of what it is worth. I need ti to ontouched remove the money and add the value of the numbervalue to leaderstats.Cash.Value

0

I cant explain it any better than that unless you can come look at it

0

So you're saying the "money" is on a conveyor, and when it gets to the end or something, it removes the money and adds money to something. And when you touch that something, you get the cash?

0

No, when the money touches the end, it goes straight to your cash, there is no collector, just like in Miners Haven.

0

Ohhh, I see. Okay, let me edit my script and it should work this time.

0

Alright, thanks in advance :)

0

I tried. Also I'm doing this server sided and not client sided as I think changing values client sided only lets you see the change but not others.

0

this will work with filteringenabled right? if not its fine though

0

and inside of local player i have a numbervalue that corresponds to the tycoon either 1, 2, 3, or 4. How would I use that for the playername?

0

It SHOULD work the FIlteringEnabled. Just try it out and see if it works. :P

0

And um, how do players claim the tycoon? Is it automatic? I assumed you have a part that a player touches and makes them owner.

0

it is automatic, it detects the lowest number that is empty

0

Im sorry... I should have told you, is that a problem?

0

Okay...um. You can edit my script so the plrname would be from a value. The game will set the value with the player's name.

0

but that is in localplayer... you cant access localplayer from a server script. Or can i use this script inside of a local script?

0

This script can't be used in a localscript. Um, you can use RemoteEvents to send the player's name to the server. Wow this comment section is getting long...

0

welll... you see... i am really bad at remote events being that i just "learned" how to use them like a month ago and i took a break for like 2 weeks because i was stuck tyring to find out how to use them, i feel like i am asking too much...

0

Im trying something, im putting a localscript inside of a numbervalue, how would i detect when the numbervalue changes to 2?

0

If you need help with RemoteEvents, you can make a new question about it or read about it in the Roblox wiki. Also I need to go, sorry.

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