Start a local script from server on Roblox studio - lua

I have a map which I would like to load in the workspace. The map also comes with its own local scripts. However, I don't know where to place them in the player. Maybe I can put them in StarterPlayerScripts and then start them from the server(if Roblox studio has such a functionality).

You can start the local script by simply changing his localscript.Disabled bool value, just change their disabled value to false inside properties when you create them. Example:
localscript.Disabled = true
--Disables localscript
--------------------------------------
localscript.Disabled = false
--Enables it

Check inside the LocalScript for any code statements of script.Parent and put the LocalScript inside whatever the Parent is.

Related

How to get the Roblox Proximity to open a store Frame

I read through the Roblox Developer Hub on how to make a ProximityPrompt work, and I can get it to do certain things, but I want to be able to open in game gui stores with one. I can't find how to call into the Frame to make it visible, and I can't find how to get the Frame to look for the correct trigger.
Below is what I added to the Frame localScript
local prompt = game:GetService("ProximityPromptService")
local button = game.Workspace.MinerStore.ProximityPrompt.Triggered:WaitForChild()
local function prompt(PromptObject, player)
frame.Visible = not frame.Visible
And then this is what my Prompt script shows.
local frame = game.StarterGui.Miners:WaitForChild("Frame")
game.Workspace.MinerStore.ProximityPrompt.Triggered:Connect(function(player)
--game.StarterGui.Miners.Frame:Connect(function(player)
-- frame.Visible = not frame.Visible
--end)
end)
I took all of this right from the developer hub and tried to make it my own, but for reasons I don't understand the two don't connect.
Your commented out code shows that you are making a common mistake. UI that is placed in the StarterGui acts as a template. It is copied into each player's PlayerGui when their character spawns. You appear to be trying to modify the UI template, not the actual UI that the specific player sees.
Since a ProximityPrompt can be observed in a LocalScript, you can directly listen for the trigger in the UI LocalScript.
local prompt = game.Workspace.MinerStore.ProximityPrompt
local frame = script.Parent
prompt.Triggered:Connect(function()
frame.Visible = true
end)

Roblox how can I search for a cloned item on the player

So I am trying to make a change color for my name GUI but I do not know how to get the cloned GUI item inside of the player. And the problem is I am new to RBLX studio and do not know how to start with this so anything would help ;)
If I understand the question correctly, you could clone the GUI from ReplicatedStorage and place it into the player's head. You could do this by putting these lines of code in a server-side script in ServerScriptService.
local ReplicatedStorage = game:GetService("ReplicatedStorage") -- If you put the GUI inside of ServerStorage you could change the service to get ServerStorage
game.Players.PlayerAdded:Connect(function(player)
local playerTagClone = ReplicatedStorage:WaitForChild("NameOfYourGUI"):Clone() -- Replace "NameOfYourGUI" to the GUI inside of ReplicatedStorage
playerTagClone.Parent = game.Workspace:WaitForChild(player.Name).Head
end)
If you would like to search for an item you can use ItemParent:FindFirstChild("ItemName") -- Of course you would change the ItemParent and ItemName to what they say.
This code has not been tested, so let me know if you have any issues with the code or if you have any questions!

Roblox Studio: NPC Humanoid, disabling climbing

I'm very new to Roblox studio and trying to get some basic functionality working. I am spawning some NPCs, and I would like to prevent them from climbing ladders. After reading documentation, it seems I should be able to do this by using Humanoid:SetStateEnabled(Enum.HumanoidStateType.Climbing, false). I am inserting that code right after I create the NPC as follows:
local function spawnEnemy()
local enemy = ServerStorage.Enemies.Zombie:Clone()
enemy.Parent = workspace.Enemies
print("Setting climbing to false")
enemy.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Climbing, false)
print(enemy.Humanoid:GetStateEnabled(Enum.HumanoidStateType.Climbing))
enemy.Humanoid.StateEnabledChanged:Connect(function()
print("state changed")
end)
end
The output as I start the game looks like:
Setting climbing to false
false
This is just what I would expect, and also note it does not output "state changed" so I know that no other part of the code is interfering.
However, this doesn't actually prevent the NPC from climbing, and in fact if I immediately type into the console (where it says "Run a command" at the bottom of roblox studio) this command:
print(workspace.Enemies.Zombie.Humanoid:GetStateEnabled(Enum.HumanoidStateType.Climbing))
The output is true.
Why doesn't the variable "stick"? Do I need to put this code somewhere else?
SetStateEnabled doesn't seem to replicate to the client. Your Run-a-command command executes against the client's workspace, and there it is still true.
If you put the same on the server (say add the following into a workspace script):
spawn(function()
while (true) do
print(workspace.Enemies.Zombie.Humanoid:GetStateEnabled(Enum.HumanoidStateType.Climbing))
wait(0.5)
end
end)
...you'll see that on the server, that property is in fact false.
Update:
to set it on the client, you can just hook up a handler on your Enemies folder, that will always set the Humanoid's climbing state for all your zombies:
workspace.Enemies.ChildAdded:Connect(function(child)
if (child.Name == "Zombie") then
child:WaitForChild("Humanoid"):SetStateEnabled(Enum.HumanoidStateType.Climbing, false)
end
end)
just put that above into a LocalScript in StarterPlayerScripts.

How do I get localplayer data from a leaderboard? (Roblox)

I'm new to Lua and Stack so I apologize in advance.
I'm currently using a tycoon kit to create a Roblox game, and the player's money value only shows up on the leaderboard, but nowhere on the screen. This can make it hard to know how much money you have on console and mobile, so I'm trying to set up a GUI to display the player's amount of money on the screen. Now, setting up the GUI isn't the issue, knowing what to set the text value on the GUI is.
I do not know how to upload am image, but the path in my workspace looks a bit like this:
Players (on the first tab of the workspace)-> Player-> leaderstats-> Cash
I've tried to grab the variable (named "Cash") like this: game.Players.Player.leaderstats.Cash.Value but because I'm not named "Player", it didn't work. I've tried replacing it with LocalPlayer (looked like game.Players.LocalPlayer.leaderstats.Cash.Value), but that also didn't work. It only works when I replace "Player" with my username (game.Players.Username.leaderstats.Cash.Value), but I want this to work for other players besides me.
I've also tried to locate the original variable, but because I did not make the kit I'm at a loss. I've looked in every script that comes with it, but could not find anything.
When I try to set the text to these values, nothing happens. The error message I get falls along the lines of Player is not a valid member of Players.
Any help would be greatly appreciated!
LocalPlayer Is a variable which is only on the client side to get the leaderstats of the LocalPlayer You need to use a local script instead of a normal script
Now i will show you how you can display it first create your "ScreenGui" then create a "TextLabel" under the ScreenGui And finaly create a "LocalScript" Under the TextLabel Now the code should be in the LocalScript
game.Players.LocalPlayer.leaderstats.Cash.Changed:Connect(function(NewValue) --Chnage Cash to your stat
script.Parent.Text = "$"..NewValue
end)
at the start of the script put this:
local plr = game:GetService("Players").LocalPlayer
and at the part where it puts the money on the screen:
(assuming the local script is in the textbox the money is in)
while true do
script.Parent.Text = plr.leaderstats.Cash.Value
wait()
end
and that's all you have to do!
raw paste (just copy and paste this into a localscript inside a textbox)
local plr = game:GetService("Players").LocalPlayer
while true do
script.Parent.Text = plr.leaderstats.Cash.Value
wait()
end
Because LocalPlayer is a Client-Side keyword,
Put this LOCALSCRIPT as a child in the TextLabel. The textlabel should be in a frame. the frame should be in a gui.
Game.Players.LocalPlayer.leaderstats.Cash.Changed:Connect(function(updategui)
script.Parent.Text = "$"..Game.Players.LocalPlayer.leaderstats.Cash.Value
end)

Roblox Studio Lua : Clone with local script

I created a template or when someone touches that template, it's destroyed, but it's only for that person. I try to clone the model with a local script, but it does not work.
local part2 = script.Parent.MarioBrick:Clone()
part2.Parent = game.Workspace.Camera
I believe cloning the script's parent will also clone the script itself, and run the script again. Are you doing this intentionally? If not then it can cause strange side effects to happen.
Edit: Sorry, I misread your code.
Your code looks fine. I suspect that your problem is that your LocalScript is not in a place that is run by clients. If you want a LocalScript to run, it needs to exist on a Player's model somewhere. An easy way to do this is to add the LocalScript into StarterPlayer > StarterCharacterScripts
This will clone the contents into the character when they spawn. Here's my example that seems to work :
local testPart = Instance.new("Part")
testPart.BrickColor = BrickColor.Random()
testPart.Position = Vector3.new(math.random(-10, 10), 1, math.random(-10, 10))
testPart.Parent = game.Workspace.Camera
When I go into the Test tab, I can start a server with 3 players. Each of those 3 players will see a different color cube somewhere different.

Resources