Why is my jump boost gamepass in roblox not working? - lua

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)

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.

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.

script works but nothing happens in-game in roblox studio

I am having problems with the functionality of a script and I don't know how to solve it.
In the images below attach photos of the in-game problem, this means that the whole script works and in-game the property of the visible "bframe" is false but in-game this is not shown and I want to know how I can solve it ..
in-game mode the visibility of the "Bframe" it becomes false in the property (that's fine) but in-game this is not seen..
Does anyone know how to solve it?
Button script
-- Events
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Evento = ReplicatedStorage.RemoteEvent
-- end of Events
local button = script.Parent
local frame = script.Parent.Parent.Parent.Frame
Evento.OnClientEvent:Connect(function(argumento1)
button.MouseButton1Click:Connect(function()
if frame.Visible == false then
frame.Visible = true
button.Visible = false
else
frame.Visible = false
end
end)
end)
Server script
-- Events
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Evento = ReplicatedStorage.RemoteEvent
-- end of Events
game.Players.PlayerAdded:Connect(function(player)
Evento:FireClient(player,"argumento1")
print("testing probado")
end)
Redteam / touch part script called script
local wll = script.Parent.Part
local fr = game.StarterGui.TeamChangerGui.BFrame
local function Toch()
fr.Visible = false
fr.button.Visible = false
print("visible desactivado")
end
wll.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
Toch()
end
end)
**images**
enter image description here
enter image description here
enter image description here
Is the button script a localscript? if it is then it may be to do with the fireclient although I am not good at it and I usually use fireallclients passing through the player name then checking if its the correct name on the clients side script.
Otherwise I am not sure as it is an interesting issue i have never encountered. Hope it works!

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!

ReplicatedFirst:RemoveDefaultLoadingScreen() not firing in Studio

I'm back with yet another problem. I'm trying to make a custom loading screen for my game, but RemoveDefaultLoadingScreen doesn't seem to be firing. Can anyone help me with this? Here's my code:
local Players = game:GetService("Players")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
ReplicatedFirst:RemoveDefaultLoadingScreen()
local TweenService = game:GetService("TweenService")
local Player = Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
PlayerGui:SetTopbarTransparency(1)
local Loading = ReplicatedFirst.Load
local ScreenGui = Instance.new("ScreenGui")
ScreenGui.IgnoreGuiInset=true
local Bar = Loading.Frame.TextLabel
ScreenGui.Name = "LoadScreen"
Loading.Parent = ScreenGui
ScreenGui.Parent = PlayerGui
local Info = TweenInfo.new(0.7,Enum.EasingStyle.Cubic,Enum.EasingDirection.InOut,0,true,0)
local Tween = TweenService:Create(Bar,Info,{Position=UDim2.new(0.8,0,0.6,0)})
spawn(function()
while true do
Tween:Play()
Tween.Completed:Wait()
end
end)
if not game:IsLoaded() then
game.Loaded:Wait()
end
for i=0,1,0.1 do
Loading.BackgroundTransparency=i
Bar.TextTransparency=i
Loading.Frame.Load.TextTransparency=i
wait()
end
ScreenGui:Destroy()
Everything works fine, except that the third line doesn't work in Studio. Is it supposed to be this way? Help would be greatly appreciated.
I tested it, it works just fine in Roblox Studio. Note this, though:
In studio the load screen goes away almost instantly, so you won't see much of a difference.
I'd put a wait(5) in your script before the if not game:IsLoaded() then line, that will simulate a 5 second load. Then you can play with having vs not having the ReplicatedFirst:RemoveDefaultLoadingScreen() command present, and you'll see the difference.

Resources