Roblox Lua Give LocalPlayer weapon doesn't work, - lua

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.

Related

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

I can't access the text of a TextBox in roblox LUA

Alright, So I've tried other stackoverflows, But I can't get it to work.
Heres the code
script.Parent.MouseButton1Click:Connect(function()
local plr = game.StarterGui.ScreenGui.title.Frame.plr
print(plr.Text)
local gp = game:GetService("ReplicatedStorage"):WaitForChild("GetPlr")
gp:FireServer(plr.Text)
end);
the frame.Plr part is the textbox
When I do plr.Text it doesn't get the current input.
I hope yall have good anwsers
And I hope you have a good day :D
UI elements that are placed in StarterGui act as a template. They are copied into each player's PlayerGui when their Character spawns in the world.
Your issue is that a player has put text into their copy of the ui, which is located in the PlayerGui, and you are trying to pull that text out of the template in StarterGui.
So in your LocalScript, try updating the path to the text box to point at the player's PlayerGui :
local PlayerService = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
script.Parent.MouseButton1Click:Connect(function()
local pg = PlayerService.LocalPlayer.PlayerGui
local plr = pg.ScreenGui.title.Frame.plr
print(plr.Text)
local gp = ReplicatedStorage.GetPlr
gp:FireServer(plr.Text)
end)

Roblox leaderstats will not display

So I have tried many variations of leaderstats scripts. Here is one in which should work just fine to my knowledge..... any thoughts on this? leaderstats gui will not display, but the script functions as I can tell through playing the game in studio to test and i notice under player it creates the folder and int value etc.
function showLeaderstats(player)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Cash = Instance.new("IntValue",leaderstats)
Cash.Name = "Cash"
Cash.Parent = leaderstats
end
game.Players.PlayerAdded:Connect(showLeaderstats)
It works fine for me. Make sure the leaderboard isn't minimized, the code is in a script and not a local script, the script is in ServerScriptService or the workspace.
Hey sorry to see that no one responded. You should try:
instead of a folder do this:
local leaderstats = Instance.new("IntValue")
--after that, you can assign it's parent to:
leaderstats.Parent = stats
Let me know if this worked!

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