#Question
1 messages · Page 1 of 1 (latest)
idk why you would pass it in since you don't even use it
It works only if its in there, but when i remove it the whole script doesn't work
@surreal void what is it
i mean do you use it anywhere else?
when you do :FireServer() does it have the parameter in there?
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
you use .Touched
ALr
May can i ask, where did you learn/write "job"?
why?
if you don't need it don't use it
But, why did you come up with job, why not just player
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?
you use .Touched on the parts and increment player's coins
Part.Touched:Connect(fucntion(hit))
it's like what/who touched the part
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")
So OnServerEvent is when remote is used?
wait
i will use this
Reading documentions is also very helpful btw.
https://create.roblox.com/docs/reference/engine/classes/RemoteEvent#OnServerEvent
** You are now Level 15! **
So if i were to do this would it go in serverscriptservice?
In my leaderstats script?
This is my leaderstats script in ServerScriptService:
How would I connect this to a part in my workspace?
(My remotevent is called CoinEvent btw)
I read it but i just need an example pls
I can learn it from there
also
fireserver aint poppin up
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
should i use fireclient instead
Bad approach, player can abusing the stats. This is why you should use remotevent, which he is trying.
You don't need a remote event for this
how so? it's a server sided script
Okay, my apologize.
No, you use FireServer.
When should i use remoteEvent then
Mostly for UI i belive.
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
wdym for one person?
mhm
so in this case
i want the block to be for everyone
does that mean i get rid of the remotevent
yes
Here is my leaderstats now:
** You are now Level 5! **
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
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)
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)
i edited it
** You are now Level 6! **
retry
yw
I need to learn it tho
yes, good luck
what is in the output?
Lemme test
k
it says Player is not a valid member of DataModel "Game"
@surreal void
are you sure you wrote it like this?
local player = game.Players:GetPlayerFromCharacter(character)
im pretty sure its this line
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
if you make it inside a server script yes
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
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
and I would make a serverscript that recieves that remote event ?
exactly
so localscript in starterGui
and another script(seperate from leaderstats) in serverScriptservice?
yes
and i would use fireserver? or firecleint
if you fire from the client you use fireserver if you fire from the server you use fireclient
in this case is it from client or server
so fire server
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
No, but i am currently working on one with a group of people
oh alr
How do i make the block teleport after It gets touched? in randonm location
@surreal void
Buy Assets/Scripts: https://www.patreon.com/erexx/shop
Become Better Developer:: https://www.patreon.com/ErExx
Discord: https://discord.gg/2aNFFssgfR
Roblox Group: https://www.roblox.com/groups/9386564/ErExx-Inc#!/about
epidemic sound: https://www.epidemicsound.com/music/search/
should be almost the same thing