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

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

Asked by 6 years ago
Edited 6 years ago

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

0
Can you post the code you've tried? OldPalHappy 1477 — 6y
0
I have tried with remote events but i suck with them, how do i post script here in a readable way? giantjdd 5 — 6y
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. User#20279 0 — 6y
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 giantjdd 5 — 6y
View all comments (2 more)
0
bump giantjdd 5 — 6y
0
Local Scripts don't work in workspace. OldPalHappy 1477 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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) 

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 giantjdd 5 — 6y
0
I use Gyazo to show screenshots to people. So...yeah. User#20279 0 — 6y
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 giantjdd 5 — 6y
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 giantjdd 5 — 6y
View all comments (18 more)
0
I cant explain it any better than that unless you can come look at it giantjdd 5 — 6y
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? User#20279 0 — 6y
0
No, when the money touches the end, it goes straight to your cash, there is no collector, just like in Miners Haven. giantjdd 5 — 6y
0
Ohhh, I see. Okay, let me edit my script and it should work this time. User#20279 0 — 6y
0
Alright, thanks in advance :) giantjdd 5 — 6y
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. User#20279 0 — 6y
0
this will work with filteringenabled right? if not its fine though giantjdd 5 — 6y
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? giantjdd 5 — 6y
0
It SHOULD work the FIlteringEnabled. Just try it out and see if it works. :P User#20279 0 — 6y
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. User#20279 0 — 6y
0
it is automatic, it detects the lowest number that is empty giantjdd 5 — 6y
0
Im sorry... I should have told you, is that a problem? giantjdd 5 — 6y
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. User#20279 0 — 6y
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? giantjdd 5 — 6y
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... User#20279 0 — 6y
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... giantjdd 5 — 6y
0
Im trying something, im putting a localscript inside of a numbervalue, how would i detect when the numbervalue changes to 2? giantjdd 5 — 6y
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. User#20279 0 — 6y
Ad

Answer this question