Create phone and call friends in roblox studio - lua

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.

Related

How can I make an exclusive graphical interface only activate when a user has a gamepass in Roblox Studio?

I am starting to program in roblox, and I am making a Menu only for users who have a gamepass, I would like to know how I can make an exclusive graphical interface appear when a user has a gamepass, and the error here is that when a user buy that gamepass automatically the exclusive interface is activated to all the users of the server, I would like to know how to fix this problem.
The Script is on ServerScriptService
local MarketPlaceService = game:GetService("MarketplaceService")
local GamePass = 100725261
local Tool = game.StarterGui.ScreenGui.TPMenu
function compra(jugador)
local loTiene = false
local success, errorMensaje = pcall(function()
loTiene = MarketPlaceService:UserOwnsGamePassAsync(jugador.UserId, GamePass)
end)
if loTiene then
game.StarterGui.ScreenGui.TPMenu.Visible = true
end
end
game.Players.PlayerAdded:Connect(function(player)
compra(player)
end)
I tried to made this in a LocalScript and is not working
StarterGui is put into each Player's PlayerGui after they spawn, so editing it for one user would mean that other users would also see the changes after respawning. A better option would be to modify PlayerGui instead, like this:
function compra(jugador)
local loTiene = false
local success, errorMensaje = pcall(function()
loTiene = MarketPlaceService:UserOwnsGamePassAsync(jugador.UserId, GamePass)
end)
if loTiene then
jugador.CharacterAdded:Connect(function() -- Ran every time the player spawns
workspace:WaitForChild(jugador.Name) -- Wait for player to finish spawning
jugador.PlayerGui.ScreenGui.TPMenu.Visible = true
end)
end
end
Keep it as a Script in ServerScriptService.

Other players can not see an object duplicate

I have this script that duplicates an object and teleports it to the player when the GUI button is pressed (You can think of GMod to make things easier). It is stored in a LocalScript inside the button and when you press it, but it's only visible for the player that clicked the button.
I'm not exactly sure how I would solve the problem or what the problem is, but I think it's because it's all stored into a LocalScript. I'm new to Lua and Roblox game development and I didn't really take any lessons on it, I'm just working from my memory and experience. Any and all suggestions are greatly appreciated. Also, if I need to give more information, please ask and I will provide it.
My script:
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
local rag = game.Lighting.ragdolls_presets["Wood Crate"]:Clone()
local X = player.Character.UpperTorso.Position.X
local Y = player.Character.UpperTorso.Position.Y + 10
local Z = player.Character.UpperTorso.Position.Z
rag.Parent = game.Workspace.ragdolls
local children = rag:GetChildren()
for i = 1, #children do
local child = children[i]
child.Position = Vector3.new(X,Y,Z)
end
end)
Thank you in advance!
When you clone something in a LocalScript, it only clones on the client side. Changes done on the client side never gets replicated to the server side, however all changes done on the server side would get replicated to all clients, which are the players.
So to fix this you'd need to use RemoteEvents, which is a way for the client to tell the server to do something.
So instead of doing this in a LocalScript
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
local rag = game.Lighting.ragdolls_presets["Wood Crate"]:Clone()
local X = player.Character.UpperTorso.Position.X
local Y = player.Character.UpperTorso.Position.Y + 10
local Z = player.Character.UpperTorso.Position.Z
rag.Parent = game.Workspace.ragdolls
local children = rag:GetChildren()
for i = 1, #children do
local child = children[i]
child.Position = Vector3.new(X,Y,Z)
end
end)
Put a new RemoteEvent in game.Replicated Storage, then:
This should be the LocalScript
local Event = game.ReplicatedStorage.RemoteEvent
script.Parent.MouseButton1Click:Connect(function()
Event:Fire()
end)
And this should be the ServerScript (or Script for short)
local Event = game.ReplicatedStorage.RemoteEvent
Event.OnServerEvent:Connect(function(player)
local rag = game.Lighting.ragdolls_presets["Wood Crate"]:Clone()
local X = player.Character.UpperTorso.Position.X
local Y = player.Character.UpperTorso.Position.Y + 10
local Z = player.Character.UpperTorso.Position.Z
rag.Parent = game.Workspace.ragdolls
local children = rag:GetChildren()
for i = 1, #children do
local child = children[i]
child.Position = Vector3.new(X,Y,Z)
end
end)
Also, it is very important to do server-side validation when using RemoteEvents, for example: instead of checking whether a player has enough money to spawn something in a LocalScript before the RemoteEvent is fired, it should be done in both LocalScript and the ServerScript. The cause for this is that players can change anything in their client side, so information from the client can NOT be trusted. Optionally you can also have time-outs in each side because, lets say a player has millions of money, he can keep executing the RemoteEvent hundreds of times in under a minute which can crash the server or cause extreme lag. So a 3 second - 1 minute time out is sometimes necessary
More information about Roblox's Client-Server Model: https://create.roblox.com/docs/scripting/networking/client-server-model
More information about Roblox RemoteEvents: https://create.roblox.com/docs/reference/engine/classes/RemoteEvent

How can I make something happen when I buy a DevProduct (Roblox LUA)

I have made a major part of the code, but I am stuck in the important part. Here is what I'm doing:
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local productID = 1218445231
local productInfo = MarketplaceService:GetProductInfo(productID, Enum.InfoType.Product)
script.Parent.MouseButton1Click:Connect(function()
local function promptPurchase()
local player = Players.LocalPlayer
MarketplaceService:PromptProductPurchase(player, productID)
purchased = true
end
end)
if purchased == true then
--stuck here (if you don't understand, the tsunami that I've made is supposed to become visible and start moving towards the map, however the part is in "Workspace". The button is in "StarterGUI". Please help.)
end
EDIT: Now updated the code, still don't know what to do. Do I get the workspace Service? If so, how do I code it that it sets the transparency of the tsunami to "0", and starts moving? This is my code:
local MarketplaceService = game:GetService("MarketplaceService")
local player = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PurchaseEvent = ReplicatedStorage.PurchaseEvent
local productID = 1218445231
script.Parent.MouseButton1Click:Connect(function()
PurchaseEvent:FireServer(productID)
end)
if MarketplaceService:PlayerOwnsAsset(1218445231) then
--Make tsunami become visible and start moving
end
In the docs for MarketplaceService, there's a note
the callback ProcessReceipt which must be well defined so that transactions do not fail.
After the purchase prompt is shown to the player, ProcessReceipt is called with the results of their choice. So that callback is how you make something happen after a user buys something.
A good structure for this kind of code is to have product purchases handled in a server Script, and to have UI elements communicate purchase intents using RemoteEvents. So do some setup :
Create a RemoteEvent in ReplicatedStorage, name it something like "PurchaseEvent"
Create a Script in ServerScriptService
Then update your LocalScript to look like this :
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PurchaseEvent = ReplicatedStorage.PurchaseEvent
local productID = 1218445231
-- listen for when players click the button to buy the product
script.Parent.MouseButton1Click:Connect(function()
-- tell the server that we want this product
PurchaseEvent:FireServer(productID)
end)
Then add this code to the server Script to handle the purchase :
local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PurchaseEvent = ReplicatedStorage.PurchaseEvent
-- listen for when players want to buy things :
PurchaseEvent.OnServerEvent:Connect(function(player, productID)
-- show the purchase prompt to the user
MarketplaceService:PromptProductPurchase(player, productID)
end)
-- Define what should happen if a player buys something
-- NOTE - ADD FUNCTIONS FOR EACH SPECIFIC PRODUCT
local productHandlers = {}
productHandlers[1218445231] = function(player)
print("TODO : spawn a tsunami")
end
-- Listen for when someone clicks on any of the buttons in the purchase prompt
MarketplaceService.ProcessReceipt = function(receiptInfo)
-- Find the player who made the purchase in the server
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
-- The player probably left the game, don't charge them yet
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- Look up handler function from 'productHandlers' table above
local handler = productHandlers[receiptInfo.ProductId]
if not handler then
error(string.format("No handler is defined for %d", receiptInfo.ProductId))
end
-- Call the handler function and catch any errors
local success, result = pcall(handler, player)
if not success or not result then
local message = table.concat({
"Error occurred while processing a product purchase",
" - ProductId: " .. tostring(receiptInfo.ProductId),
" - Player: " .. player.Name,
}, "\n")
warn(message)
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- IMPORTANT: Tell Roblox that the game successfully handled the purchase
return Enum.ProductPurchaseDecision.PurchaseGranted
end
If you want to check if a user has bought something in the past and you don't want to charge them again, you can always check before you show the purchase prompt with the MarketplaceService:PlayerOwnsAsset function.

Why won't it remove my items from my Backpack

I'm going to cut to the chase. Whenever this script executes:
local hotkey = Enum.KeyCode.P
local plr = game.Players.LocalPlayer
local char = plr.Character
local backpackItems = plr.Backpack:GetChildren()
local UIS = game:GetService("UserInputService")
local open = false
UIS.InputBegan:Connect(function(key, gp)
if key.KeyCode == hotkey then
char.UpperTorso.CFrame = CFrame.new(132.109, -84.7, 22.002)
local takenItemsStorageFolder = Instance.new("Folder")
takenItemsStorageFolder.Parent = game.ReplicatedStorage
takenItemsStorageFolder.Name = "Removed Items From ".. plr.Name
backpackItems.Parent = takenItemsStorageFolder
end
end)
It will teleport your player to a certain location on a map, but the lines involving variables "backpackItems", and "takenItemsStorageFolder" are trying to remove the tools/items in the player's Backpack. But the script won't complete this on execution.
Some other information:
This script is inside of a TextLabel in a ScreenGui.
(More info if requested)
I see two problems here:
You are creating a table with the backpack items when the script is first executed. Later when the "P" button is pressed you then want to move those objects to the takenItemsStorageFolder. But at that point there might be different items in the Backpack folder.
You are trying to parent the backpackItems table to the takenItemsStorageFolder object, but that does not work with a table. Instead you have to iterate through the actual objects (children of the Backpack) and parent each one.
So as a solution instead of
backpackItems.Parent = takenItemsStorageFolder
I would suggest you do:
for i,v in pairs(plr.Backpack:GetChildren()) do
v.Parent = takenItemsStorageFolder
end

Roblox Studio Admin GUI set player scores

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.

Resources