Roblox Studio Admin GUI set player scores - lua

Hi there i'm a little stuck on how i would set a players cash through a admin gui i'm not to familiar with this language and could use a little help.
here is what the gui looks like
GUI Image
Explorer Image
code Image
here is what i have so far not sure if im on the right lines or not aha
button = script.Parent.MouseButton1Click:connect(function()
local stat = Instance.new("IntValue")
stat.Parent = script.Parent.Parent.casgplayertext.Text
stat.Name = "Cash"
stat.Value = script.Parent.Parent.cashetxt
game.Players.childAdded:connect()
end)

The statistics values should be children of a model or folder object named 'leaderstats', located in the player (for instance: Player1>leaderstats>Cash). So you need a script that creates this 'leaderstats'-named object with the statistics you want. So you would get something like this:
local players = game:WaitForChild("Players")
local function initializeLeaderstats(player)
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
local cashStat = Instance.new("IntValue", stats)
cashStat.Name = "Cash"
stats.Parent = player
end
players.PlayerAdded:connect(initializeLeaderstats)
Then you need some code to manipulate the value of someones cash statistic in another script. You can write a function that uses 2 parameters: the player name and the amount of cash.
local players = game:WaitForChild("Players")
local function setCashValue(playerName, value)
local player = players:FindFirstChild(playerName)
if player then
local leaderStats = player.leaderstats
local cashStat = leaderStats.Cash
cashStat.Value = value
end
end
You can call this function when you have clicked the 'Submit' button with the 2 parameters: the player name and the amount of cash.

Related

attempt to index nil with leaderstats

I'm making a game where you ram cars into houses and it unanchored the parts that are touched by a part in the front of the car. I want to have it so that whenever you unanchor a part, you get a coin
local HitPart = script.Parent
local function onTouch(otherPart)
local player = otherPart.Parent
if otherPart then
local player = game.Players:FindFirstChild(otherPart.Parent.Name)
if otherPart then
game.Players.LocalPlayer.leaderstats.coins.Value = game.Players.LocalPlayer.leaderstats.coins.Value + 1
end
end
end
HitPart.Touched:Connect(onTouch)
HitPart is the part that is touching the other parts. However, I keep getting "attempt to index nil with 'leaderstats'" error. does anyone know whats wrong?
Have you created the leaderstats inside the player? Here's an in-depth article about In-game leaderboards by Roblox
The error is telling you that you are trying to access the leaderstats of a player that doesn't exist.
You have a few issues.
Since this is (probably) a Script, game.Players.LocalPlayer doesn't exist. LocalPlayer only exists in LocalScripts.
Since the Touched signal will fire for any object that touches it, you need to add safety checks that the player object actually exists
To make finding a player easier, I would recommend the Players:GetPlayerFromCharacter function. You pass it a Model from the Workspace, and it tells you if you've got a Player.
local HitPart = script.Parent
local function onTouch(otherPart)
local characterModel = otherPart.Parent
local player = game.Players:FindPlayerFromCharacter(characterModel)
if player then
local coins = player.leaderstats.coins
coins.Value = coins.Value + 1
end
end
HitPart.Touched:Connect(onTouch)

Why is my jump boost gamepass in roblox not working?

So I decided to make a jump boost gamepass in roblox but when I test and I have my gamepass it doesn't work.
here is my code
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local PlayerUserID = Players.LocalPlayer.UserId
print(PlayerUserID)
Players.LocalPlayer.CharacterAdded:Connect(function(char)
print(MarketplaceService:UserOwnsGamePassAsync(PlayerUserID, 21723718))
if MarketplaceService:UserOwnsGamePassAsync(PlayerUserID, 21723718) then
char.Humanoid.UseJumpPower = true
char.Humanoid.JumpPower = 100
end
end)
it is a server script on ServerScriptService
I cant see any output that comes from the script.
You cannot use LocalPlayer in a Server Script. You will have to get the player via other methods.
Check out the Roblox gamepass guide.
Your server script is targeting an object that doesn't exist. game.Players.LocalPlayer is only defined in localscripts.
To get around this, use Players.PlayerAdded
Use this code instead
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
if MarketplaceService:UserOwnsGamePassAsync(PlayerUserID, 21723718) then
char.Humanoid.UseJumpPower = true
char.Humanoid.JumpPower = 100
end
end)
end)

IntValue changing but not shown

I'm scripting a lawn-mowing game in Roblox Studio and I've come across a problem. So every time I cut the grass(trawa) the IntValue goes up by 1. It works fine when it is assigned to a pick-up object and the points go straight to Player's Inventory folder:
local trawa = script.Parent
local function collect(otherPart)
local player = game.Players:FindFirstChild(otherPart.Parent.Name)
if player then
local trawaType = trawa.Name
local trawaStat = player.Inventory:FindFirstChild(trawaType)
if trawaStat then
trawa:Destroy()
trawaStat.Value = trawaStat.Value + 1
end
end
end
trawa.Touched:Connect(collect)
So that script works fine, but that's not the way I want it to work. I want the points to be assigned directly after cutting grass, not after I collect a pick-up it drops. So I changed the script above so that the points are assigned to the tool's inventory and then are copied to player's inventory.
local trawa = script.Parent
local function onTouch(otherPart)
local tool = otherPart.Parent
if tool:IsA('Tool') and tool.Kosa.Value == true then
trawa.Parent = nil
local trawaType = trawa.Name
local trawaStat = tool.Inventory:FindFirstChild(trawaType)
trawaStat.Value = trawaStat.Value + 1
print(trawaStat.Value)
wait(3)
trawa.Parent = workspace
end
end
trawa.Touched:Connect(onTouch)
The value does indeed change because it goes up when I print it, but it's not changing in the properties and is not registered by other scripts, because it's not copied to player's inventory.
Then this is the script in ServerScriptService that should transfer points from the tool to player:
local starter = game:GetService("StarterPack")
local tool = starter:FindFirstChildWhichIsA('Tool')
local player = game:GetService("Players").LocalPlayer
function points(player)
player.Inventory.Trawa2.Value = player.Inventory.Trawa2.Value + tool.Inventory.Trawa2.Value
tool.Inventory.Trawa2.Value = 0
end
tool.Inventory.Trawa2.Changed:Connect(points)
Changing IntValue to NumberValue doesn't solve the problem.
Use a local script with a RemoteEvent that runs it in server script, local scripts are client side. So they don't save to the server, but if you run it on the server, it saves.
Click this link if you want to know more about RemoteEvents.
https://roblox.fandom.com/wiki/Class:RemoteEvent

Roblox Lua Give LocalPlayer weapon doesn't work,

My code: https://justpaste.it/87evk
local original = game:GetService("ReplicatedStorage"):FindFirstChild("CloneSmoke")
local tool = script.Parent
local copy = original:Clone()
tool.Activated:Connect(function()
print("Running...")
local sound = script.Parent.Sound
copy.Parent = script.Parent.Handle
sound:Play()
wait(3)
tool:Destroy()
local plr = game.Players.LocalPlayer
local weapon = game.ReplicatedStorage.Jutsus.Momoshiki["Momoshikis Sword"]
local w2 = weapon:Clone()
w2.Parent = plr.Backpack
end)
Idk what i have to do here to get the Player and give him a Weapon.I tried much but i dont get the right Soloution.
It were nice wenn you help me
First off, make sure this is in a LocalScript
Also change local original = game:GetService("ReplicatedStorage"):FindFirstChild("CloneSmoke") to local original = game:GetService("ReplicatedStorage"):WaitForChild("CloneSmoke") This is because the script loads faster than items in the game, so chances are, the sword hasn't loaded into the game by the time the script runs; the script won't work if it doesn't find the object you are trying to reference.

Create phone and call friends in roblox studio

Hello I would like to know if someone knows how it would be possible to create a phone to call friends, for example you see the list of people connected on the phone and call one and when he answers you can have a private chat with him..
Any ideas or way to do this? I've looked everywhere and can't find a solution..
first, before we start making a chat function, we're going to need a list of players. Create a frame to be the phone, then add the following local script:
local frame = script.parent
local plrs = game:GetService("Players")
local plr = plrs.LocalPlayer
for i,v in pairs(plrs) do
if v.Name ~= plr.Name then
local optionButton = Instance.new("TextButton")
optionButton.Text = v.Name
optionButton.Parent = frame
optionButton.MouseButton1Click:Connect(function()
--They chose a player to talk to
--We're going to create a value on the player so we can remember who they're talking to:
local val = Instance.new("StringValue")
val.Name = "chattingTo"
val.Value = v.Name
val.Parent = plr
end)
end
end
When they click on that button, we know they want to chat to the player V. You could add in some sort of ringing system so the other player can choose to accept/decline the call, but that isn't important. For the chat, to communicate between players, we're going to need a remove event (called "ChatEvent" under Replicated Storage) and a scrolling frame for the messages to show on.
Make a localscript under the chat frame, with:
local rs = game:GetService("ReplicatedStorage")
local event = rs:WaitForChild("ChatEvent")
event.OnClientEvent:Connect(function(msg, from)
local textlabel = Instance.new("TextLabel")
textlabel.Text = from.Name..": "..msg
textlabel.Parent = script.Parent
end)
The script above will handle showing messages it receives. Now we want to be able to send messages, so add to the bottom of that localscript:
local inputBox = script.Parent.myTextBox --obviously change all variables to the route in your game
local sendButton = script.Parent.sendButton
local uis = game:GetService("UserInputService")
function sendChat()
local msgToSend = inputBox.Text
local sendTo = game.Players.LocalPlayer.chattingTo.Value
event:FireServer(sendTo, msgToSend)
local textlabel = Instance.new("TextLabel")
textlabel.Text = game.Players.LocalPlayer.Name..": "..msg
textlabel.Parent = script.Parent
end
sendButton.MouseButton1Click:Connect(sendChat)
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Return then
sendChat()
end
end)
So now whenever we either click the send button or press our enter/return key, it will fire an event on the server. And when an event on the client is fired by the server, it will add a message to the chat. Now we need to just join them together with the following (server) script:
local rs = game:GetService("ReplicatedStorage")
local event = rs:WaitForChild("ChatEvent")
event.OnServerEvent:Connect(function(from, to, msg)
--The variable 'to' is who we want to send it to - but it's a string! so:
local sendTo = game.Players[to]
event:FireClient(sendTo, msg, from)
end)
And that (should) be it. This would work, but it could face moderation action, as it doesn't use roblox's chat filter, so I recommend you integrate something with that.

Resources