#Question

1 messages · Page 1 of 1 (latest)

reef agate
#

giveCurrency.OnServerEvent:Connect(function(player, job)
local leaderstats = player.leaderstats
local coins = leaderstats.Coins
coins.Value += 50
end)

what does the second parameter, "job" mean in this?

surreal void
#

idk why you would pass it in since you don't even use it

reef agate
#

It works only if its in there, but when i remove it the whole script doesn't work

#

@surreal void what is it

surreal void
#

i mean do you use it anywhere else?

#

when you do :FireServer() does it have the parameter in there?

reef agate
#

I didn't use the fireserver anywhere yet

#

Ok this is my leaderstats: game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder", plr)
leaderstats.Name = "leaderstats"

local coins = Instance.new("IntValue", leaderstats)
coins.Name = "Coins"
coins.Value = 0

end)

local giveCurrency = game.ReplicatedStorage.CoinEvent

giveCurrency.OnServerEvent:Connect(function(player, job)
local leaderstats = player.leaderstats
local coins = leaderstats.Coins
coins.Value += 50
end)

#

How do I make it so if a player touches a block it gives them 50 coins (does that function)

#

@surreal void

surreal void
#

you use .Touched

reef agate
#

ALr

surreal void
#

if you dont event fire the event it cant work

#

btw

silent sun
#

May can i ask, where did you learn/write "job"?

reef agate
#

idk

#

i just used a random word

surreal void
#

why?

reef agate
#

What do you suggest

#

Let me recap

surreal void
#

if you don't need it don't use it

silent sun
#

But, why did you come up with job, why not just player

reef agate
#

i copied a video

#

sry

#

So i have a LeaderStats in ServerScriptService, RemoteEvent in ReplicatedStorage

#

and now I want to make a block that gives coins when touched

#

what do i do?

surreal void
#

you use .Touched on the parts and increment player's coins

#

Part.Touched:Connect(fucntion(hit))

reef agate
#

What is hit?

#

is that a created paramter

surreal void
#

it's like what/who touched the part

reef agate
#

ok

silent sun
#

So to answer your question, this is an argument.

player (first argument) will be always there in OnServerEvent, the 2.nd Arguments its optional, it doesn't need it. You can use this 2.nd argument if you want somethings like this:

event.OnServerEvent:Connect(function(player, trig)
  if trig == "buy" then
    --do buy stuff
  elseif trig == "sell" then
    --do sell stuff
  end
end)

Which you can fire from

event:FireServer("sell")
reef agate
#

So OnServerEvent is when remote is used?

surreal void
#

yes

#

but you dont need it

#

'

reef agate
#

ok

#

what do i do next to connect the remote

silent sun
sonic ironBOT
#

studio** You are now Level 15! **studio

reef agate
#

Thx

#

Wait

reef agate
#

In my leaderstats script?

silent sun
#

The 1.st section, yes.

reef agate
#

This is my leaderstats script in ServerScriptService:

#

How would I connect this to a part in my workspace?

#

(My remotevent is called CoinEvent btw)

silent sun
reef agate
#

I read it but i just need an example pls

#

I can learn it from there

#

also

#

fireserver aint poppin up

surreal void
#
part.Touched:Connect(function(hit))
      local char = hit.Parent
      local hum = char:WaitForChild("Humanoid")

      if hum and char then
            local player = game.Player:GetPlayerFromCharacter(char)
            -- coins.Value += Your value
reef agate
#

should i use fireclient instead

silent sun
surreal void
#

You don't need a remote event for this

reef agate
#

I am trying to learn remote event also

#

it woprks'

surreal void
reef agate
#

I think remoteEvent iss needeed

#

utube tutorials use it

#

guys?

#

@everyone

silent sun
reef agate
#

Wait what

#

I don't need remotes?

silent sun
reef agate
#

When should i use remoteEvent then

silent sun
#

Mostly for UI i belive.

reef agate
#

oh

#

like gui buttons?

surreal void
#

So remotes events are used to communicate between the server and client aka server script ---> local or vice versa

#

For example like freddo said you want to handle ui. you cant do that directly from a server script, so you use fire client

reef agate
#

oh

#

so if the block was only for 1 person?

surreal void
#

wdym for one person?

reef agate
#

like

#

if one person touches it

#

then it dissapears

#

but only for that persosn

surreal void
#

mhm

reef agate
#

so in this case

#

i want the block to be for everyone

#

does that mean i get rid of the remotevent

surreal void
#

yes

reef agate
#

Here is my leaderstats now:

sonic ironBOT
#

studio** You are now Level 5! **studio

reef agate
#

game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder", plr)
leaderstats.Name = "leaderstats"

local coins = Instance.new("IntValue", leaderstats)
coins.Name = "Coins"
coins.Value = 0

end)

#

How do i make it add 50 coins to a player when they touch a block i made?

#

using this leaderstat system?

#

@silent sun

#

@surreal void

#

im sorry

#

pls help

surreal void
#

part.Touched:Connect(function(hit)
  local char = hit.Parent
  local hum = char:WaitForChild("Humanoid")

  if hum and char then
     local player = game.Player:GetPlayerFromCharacter(char)
     local leaderstats = player:WaitForChild("leaderstats")
     local coins = leaderstats.Coins

     coins.Value += 50
  end
end)

reef agate
#

urs doesnt work

#

but thi workss :local part = script.Parent

part.Touched:Connect(function(hit)
local character = hit.Parent
local humanoid = character and character:FindFirstChild("Humanoid")
if humanoid then
local player = game.Players:GetPlayerFromCharacter(character)
if player then
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local coins = leaderstats:FindFirstChild("Coins")
if coins and coins:IsA("IntValue") then
coins.Value = coins.Value + 50
end
end
end
end
end)

surreal void
#

i edited it

sonic ironBOT
#

studio** You are now Level 6! **studio

surreal void
#

retry

reef agate
#

oh

#

oh it

#

works

#

thx

surreal void
#

yw

reef agate
#

I need to learn it tho

surreal void
#

yes, good luck

reef agate
#

Nvm

#

it doesnt work

#

ssorry

#

I @surreal void

surreal void
#

what is in the output?

reef agate
#

Lemme test

#

k

#

it says Player is not a valid member of DataModel "Game"

#

@surreal void

surreal void
#

are you sure you wrote it like this?

local player = game.Players:GetPlayerFromCharacter(character)

#

im pretty sure its this line

reef agate
#

ohh

#

it works now

#

thx

#

So say i make it teleport somewhere else when touched, does that work for all players to see since I did not use remoteEvent?

#

@surreal void

surreal void
#

if you make it inside a server script yes

reef agate
#

ok

#

and then with these coins, i could make a shop in Gui and make a local script that uses those coins to buy stuff right

#

That would require a remoteEvent?

#

@surreal void

surreal void
#

to manipulate gui like edit text or something yes. to manage coins and other player data you do it ONLY on the server

#

so when a plyer presses a button you use a remote event to do the buying system

reef agate
#

and I would make a serverscript that recieves that remote event ?

surreal void
#

exactly

reef agate
#

so localscript in starterGui

#

and another script(seperate from leaderstats) in serverScriptservice?

surreal void
#

yes

reef agate
#

and i would use fireserver? or firecleint

surreal void
#

if you fire from the client you use fireserver if you fire from the server you use fireclient

reef agate
#

in this case is it from client or server

surreal void
#

so fire server

reef agate
#

oh ye

#

since we press gui buttom from client

#

i really apprecieate ur help'

#

other people just brush it off

#

Have you made any games? @surreal void

surreal void
#

No, but i am currently working on one with a group of people

reef agate
#

oh alr

#

How do i make the block teleport after It gets touched? in randonm location

#

@surreal void