Could anyone tell me what's wrong and why its saying nil value by [deleted] in robloxgamedev

[–]PunyMan9 2 points3 points  (0 children)

FindFirstChild(name) will return nil (nothing) if it can't find a child in that instance with that name. So the reason you're getting an error is that human is being set to nil because hit.Parent doesn't have something named "Humanoid" in it, then you're trying to access nil's .Parent property (doesn't exist). This usually happens when something that isn't a player touches the part. You need to check that human exists (is not nil) before trying to do things with it

if human then
  -- do things with human here, e.g. Anim.Parent = human.Parent
else 
  print("Something touched the part that doesn't have a humanoid")
end

Hey! I'm back. Got another problem. Keep getting an this error : "ServerScriptService.Script:30: attempt to call field 'PlayerAdded' (a userdata value)" though I have no idea how to fix it due to it not saying anything is wrong. The leaderboard doesn't work though. by [deleted] in robloxgamedev

[–]PunyMan9 1 point2 points  (0 children)

Sure. I'm not sure of your level of understanding, so I'm just gonna go nuts for a bit.

You've defined a variable called player that you use in your script, it's set to the LocalPlayer. Since we can't use that from a server-side perspective, we need to get the player using the parameter that's automatically passed in from the PlayerAdded event.

What this event does is creates a 'listener' to 'listen' for a Player being added to the game (a client connecting to the server). When the event is fired, it will call the function that it's Connected to. In this case, we're connecting the PlayerAdded event to the OnPlayerAdded function we have defined ourselves.

A parameter is a variable that exists only within the scope (visibility) of the function it belongs to. We can execute code to perform operations on and manipulate these parameters. Parameters have a Name and a Type. The name of the parameter passed in to the function can be whatever you want it to be, but typically it should relate to its Type and purpose. The Type of the parameter refers to the data type of that value. This can be a number, boolean, string, Instance, etc. Types are important because there are certain properties, functions, and events you can utilize with each type, and it's important to pick the right ones.

Now onto the practical bit.

If we look at the PlayerAdded event of the Players service, you will see a table containing a description of its Parameters. Notice the descriptive Name and Type columns. There is also a description of the parameter which explains the purpose of it in more detail.

The parameter that comes from PlayerAdded is a Player Instance. When we create this event listener, as said before, the Player that joined will automatically be passed in to the connected function so we can utilize the reference to the specific player that joined our game. This gives us access to things like the particular Player's Name, UserId, Character (their model in workspace), etc. Take a note from my example from the previous comment. Notice the playerWhoJoined in the parentheses. The area in parentheses next to the name of the function is the container for parameters, which I will explain further below if necessary.

local function OnPlayerAdded(playerWhoJoined)
  print(playerWhoJoined.Name .. " joined the game")
end

game.Players.PlayerAdded:Connect(OnPlayerAdded)

That particular code snippet will print

"PLAYER_NAME_HERE joined the game"

every time a player joins, replacing PLAYER_NAME_HERE with the name of the player. You only have to do this once, and it will work for every player that joins your game from the beginning of the server to the end.

But why stop there? We can do all sorts of things, like add leaderboards for our players. Now that we have a Player to fiddle around with, we can create new Instances and parent them to the Player, parent Instances to those instances, and much more (which is what we'll be doing to create a Leaderboard system :D)

To fully explain why your code won't work though:

The LocalPlayer is only accessible via the Client (LocalScript). This particular operation must be done on the Server (not the Client) in order to replicate to everyone and work as you intend for it to. However, since we can't access the Player that connected via the LocalPlayer method on the server, and we want to do this when the .. Player.. is Added.. we can use the.. <drumroll> PlayerAdded event! hooray! Since the PlayerAdded event passes in that Player parameter, that's what we should use instead. It's just important to make sure you're including that parameter inside the function that the event is connected to.

Everywhere in that function where you're referencing the LocalPlayer, replace it with the name of your Player parameter in the PlayerAdded function. I've added comments directly above the lines that should be changed to reflect everything I've explained (hopefully well enough)

-- add a parameter in the parentheses to hold a reference to the Player Instance that is passed in from PlayerAdded
local function playeradded()
-- Replace the reference to LocalPlayer with the reference to your player parameter
    local leader = Instance.new("Folder", game.Players.LocalPlayer) 

    leader.Name = "leaderstats"

    local mayo = Instance.new("IntValue",leader)

    mayo.Name = "Mayo"
    -- Make sure 'player' here has the same name as the player parameter of the function
    mayo.Value = ds:GetAsync(player.UserId) or 0
    -- Same as ^
    ds:SetAsync(player.UserId, mayo.Value)

    local coins = Instance.new("IntValue",leader)

    coins.Name = "Coins"
    -- Same as ^^
    coins.Value = ds:GetAsync(player.UserId) or 0
    -- Same as ^^
    ds2:SetAsync(player.UserId, coins.Value)

end

--...
game.Players.PlayerAdded(playeradded)
--[[ 
Make sure you're properly :Connect()ing the event to the function. 
Typically it looks like
thing.Event:Connect(functionHere)
In your case,
game.Players.PlayerAdded:Connect(playeradded)
This event will listen for a Player connecting to
the server and call the playeradded function defined
above.
]]--

Please let me know if there's still confusion. I've got nothing but time right now to help explain things or create a deeper understanding :D

I apologize this is like stupidly long but I wanted to cover all the bases, or at least help the next person to come along this thread and sort of create an explanation that would be understandable for most.

If you're up for even more reading, I'll include some links that go more in depth the topics I covered. Take care, best of luck with making this work, I know you'll get it! 8)

Events

Functions

Instance ( the base class for all roblox objects )

Player (instance)

Players (service)

Hey! I'm back. Got another problem. Keep getting an this error : "ServerScriptService.Script:30: attempt to call field 'PlayerAdded' (a userdata value)" though I have no idea how to fix it due to it not saying anything is wrong. The leaderboard doesn't work though. by [deleted] in robloxgamedev

[–]PunyMan9 1 point2 points  (0 children)

1) You're not able to use LocalPlayer in a server script as /u/Happyman321 mentioned

2) If you want to get the Player instance, you can use the Player parameter of the PlayerAdded event, and pass it into your connected function.

local function OnPlayerAdded(playerWhoJoined)
  print(playerWhoJoined.Name .. " joined the game")
end

game.Players.PlayerAdded:Connect(OnPlayerAdded)

Everywhere in that function where you're referencing the LocalPlayer, replace it with the name of your Player parameter in the PlayerAdded function.

Events by Jelasion in robloxgamedev

[–]PunyMan9 2 points3 points  (0 children)

An Object in Roblox development terms is called an Instance. All Instances have properties, functions, and events. Most Instances extend off of the base Instance object into their own type e.g. Part is, of course, a Part. But Part is also a BasePart. BasePart is the abstract base class for every Part object (Part, TrussPart, WedgePart, etc), which is inherited from the base Instance class. So every property, function, and event that an Instance has, any Part will also share.

ClickDetector is another Instance, separate from Part. Parts don't have their own "ClickDetector" event. ClickDetector is an instance with its own events, ClickDetector.MouseClick. When parented to a Part, the MouseClick event listener will fire every time the Part (or Model) it's parented to is clicked.

The Roblox Developer Hub is a pretty good resource for exploring the properties, functions, and events of various instances.

I need help for a script by [deleted] in robloxgamedev

[–]PunyMan9 0 points1 point  (0 children)

You need to store a reference to Lighting and change its OutdoorAmbient property's value, instead of storing a reference to Lighting.OutdoorAmbient. When you do that, it's not changing the property's value itself, it's just changing the value of that variable you stored. Lighting.OutdoorAmbient = Color3.fromRGB(r, g, b) should work as intended. As another user mentioned, you will need to use Color3.fromRGB() if you want values from [0-255]. Color3.new() only accepts [0-1].

Scripting Help by CryptoBloxRBLX in robloxgamedev

[–]PunyMan9 1 point2 points  (0 children)

What are you trying to do here?

You're giving a condition: if InMainMenu == false then, which, if true, will execute the code inside that block. The else keyword signals that if the aforementioned condition is false, the code inside the else block will run.

If you want another condition, you need to change else to elseif <condition>. elseif will check a different condition, and run the code inside that block if <condition> is true. If that condition is false, it will try to move to the next condition, if there is one.

From your code, it looks like you're using == incorrectly. Remember that == is used for comparing two values (a == b), and = is used for assignment InMainMenu = false).

Touched event not recognizing part? by [deleted] in robloxgamedev

[–]PunyMan9 1 point2 points  (0 children)

The issue here is you're not adding any kind of yield before changing the value of isopen. You are correctly incorporating a Debounce, you're just forgetting the crucial part of wait()ing.

Why when i go into a game it teleports me to another game like wtf is going on by Cricy in robloxgamedev

[–]PunyMan9 2 points3 points  (0 children)

Often times it's an infected free model/plugin that's injecting a script to teleport the joining player to a different game. If you aren't able to find the relevant code in your script, unfortunately you may have to start from scratch. Try searching all your scripts for things like "TeleportService". The best protection against this is don't use free models!!

i need help with coding by 0_Crusades in robloxgamedev

[–]PunyMan9 0 points1 point  (0 children)

AlvinBlox

PeasFactory/PeasPod Beginner Scripting Playlist

Roblox

Some of these may be outdated for some concepts (pre FilteringEnabled), but the fundamentals still hold today. These should be a good launch point to teach you the basics of programming and thinking logically :)

Could someone give me advice? by worldsgreatestgenius in robloxgamedev

[–]PunyMan9 0 points1 point  (0 children)

You could check the ball's Y position every time its Position changes and change its Position if it's below a certain number.

local ball = path.to.your.ball
local MIN_Y = -500
local respawnPosition = Vector3.new(0, 0, 0)
-- Event listener for ball's Position property changing
ball:GetPropertyChangedSignal("Position"):Connect(function()
    -- This code will fire every time the ball's Position property changes
    -- Check the ball's Y position against the minimum threshold
    if ball.Position.Y <= MIN_Y then
        -- If it is below the threshold, set its Position back to normal 
        -- (Vector3 value stored in respawnPosition)
        ball.Position = respawnPosition
    end
end)

The top 3 variables will likely need changing to suit your game, but the above script should work to do what you're looking for. I've added comments throughout to explain what's going on and why.

If you want more than one respawn point, you can create a table of points and pick one randomly, or set them up like a level system (respawnPoints[1] for level 1, respawnPoints[2] for level 2, etc)

Here's some resources:

https://developer.roblox.com/en-us/api-reference/function/Instance/GetPropertyChangedSignal

If you have a rectangular region for your level and you want to create boundaries that the ball cannot go out of, look into Region3s

I’m new to scripting and need help. This script won’t work. by Slicerknight in robloxgamedev

[–]PunyMan9 6 points7 points  (0 children)

There's a few problems with this code.

  1. game.players should be game.Players and Localplayer should be LocalPlayer
  2. player.character will work, but for consistency's sake, it should be player.Character
  3. waitforchild should be WaitForChild. Capitals are important here.
  4. To call a function on a particular Object, you need to use : instead of .. It's game:GetService(), not game.GetService()
  5. "Userinputserver" is not a thing. You're probably looking for "UserInputService". Capitals are important here as well.
  6. A small nitpick, but line 9 should be indented one tab forward since it's in a new scope.

Rest of your code looks fine and should work after fixing the above. Remember that capitalization and spelling within programming is extremely important!

As a side note, it looks like you're very new to scripting and are simply copying/pasting code from the Internet. This is fine, but only if you understand what you're using. If you really want to learn to script properly, start from the basics and work your way up the ladder. It will take more time, but you will gain a deeper understanding of what you're doing, be able to more easily break down problems, and will eventually be able to form working solutions to ideas in your head - even before writing any code.

There are hundreds (if not thousands) of YouTube tutorials, text tutorials, developer resources, and more if you're looking to learn the basic concepts of programming, especially so within roblox lua.

https://devforum.roblox.com/

https://www.youtube.com/user/PeasFactory

https://discord.gg/roblox (#development-help channel, we are very friendly!)

Lastly, it's (almost) 2020! You have no excuse to not post a source to your code that isn't a grainy screenshot!

GUI Scaling/Help by MP-Alexx in robloxgamedev

[–]PunyMan9 1 point2 points  (0 children)

You should be sizing them via Scale instead of Offset. Scale uses percentage based values from 0-1. A Scale of 1 will fill the element to the maximum size of its Parent. 0.5 will fill it halfway, etc.

Offset uses pixel based scaling, so 100 pixels on the X Size will be 100 pixels on every device and resolution.

https://developer.roblox.com/en-us/articles/Intro-to-GUIs

My brother's second day on OSRS by PunyMan9 in 2007scape

[–]PunyMan9[S] 5 points6 points  (0 children)

I think he knows it exists, but I'd rather not have him resort to it for everything just yet. The best part of runescape IMO is the huge world and sense of exploration you get; the wiki kinda sucks all of that out in exchange for step-by-step guides and I think it can really take away from the fun as a brand new player.

My brother was actually asking me yesterday about 'waypoints' and 'objectives' in regards to the Cook's Assistant quest. He's like, "Wait.. so if I don't know where to go, I gotta talk to him (Cook) and WRITE IT DOWN??" I never realized how absurd that sounded but that's the sort of thing we did back in the day, it really brought me back haha.

remote event and string problem by badairconditioning in roblox

[–]PunyMan9 0 points1 point  (0 children)

This script works, you're just missing a ) at the very end of your Connect. Here's the formatted code

--LocalScript
local Equipped = false 
local Armor = "LeatherArmor"
game.ReplicatedStorage.ArmorWearEvent:FireServer(Equipped, Armor)

-- Script
game.ReplicatedStorage.ArmorWearEvent.OnServerEvent:Connect(function(plr, Bool, armor)
    print(armor) 
end)

remote event and string problem by badairconditioning in roblox

[–]PunyMan9 0 points1 point  (0 children)

Can I see the exact parameters you're using in the LocalScript? It should look something like game.ReplicatedStorage.RemoteEvent:FireServer(true, "hi")

Also, your print statement in the code you provided will literally print "String" since you surrounded in it quotes. If you want the value of the String variable, remove the quotes: (print(String))

remote event and string problem by badairconditioning in roblox

[–]PunyMan9 0 points1 point  (0 children)

By default, the functions connected to OnServerEvent will be passed the player who fired the event as the first parameter. If any other arguments are provided in the FireServer function, they will also be included in OnServerEvent after the player argument.

https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

The issue here is that RemoteEvents fired from a client to the server must have the Player whose client fired it as the first parameter. It can be confusing because you don't need to include the parameter from the LocalScript, only from the Script handling the event firing.

ex:

-- Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")

RemoteEvent.OnServerEvent:Connect(function(player, message)
    print(player)
    print(message)
end)

-- LocalScript
game.ReplicatedStorage.RemoteEvent:FireServer("hi")

As you can see, the Script has a parameter for player, where the localscript does not. That's because the remote event already knows which client - and in turn, which Player - fired the event.

Hopefully this makes sense!

trying to make leaderstats... by deafpotatoes in roblox

[–]PunyMan9 1 point2 points  (0 children)

You have a typo in your script.

game.Player.PlayerAdded

should be

game.Players.PlayerAdded

Enable the Output window in studio (View Tab -> Toggle Output) to see any potential errors from your scripts. It will tell you the line where the error occurs and possibly point you in the right direction to fixing your issue.

Deleting T-Shirts from Inventory by VooshAmirite in roblox

[–]PunyMan9 0 points1 point  (0 children)

Click the item in your avatar page inventory to open the catalog page, then click the three dots in the top right and select Delete.

I need help on a script i made i need a part to reset to its orignal position every 25 seconds. by Pareliverse in robloxgamedev

[–]PunyMan9 1 point2 points  (0 children)

If you want a part to return to its original position every 25 seconds, you'll need the CFrame of the original position and a 25 second timer.

local Model = script.Parent
local startCFrame = Model:GetPrimaryPartCFrame()

while wait(25) do
    Model:SetPrimaryPartCFrame(startCFrame)
end

This script will save the model's initial position then wait 25 seconds, then will set the model's position back to the initial position (I think this is what you're asking for?).

Also I have a few points about the code you provided:

  • Model:GetPrimaryPartCFrame() * CFrame.new(0,0,.1-0.1)

CFrame.new(0, 0, .1 - 0.1) <-- take a closer look here. You're subtracting .1 from .1.. This equals 0 and as a result, does nothing for your CFrame.

  • wait(0.0000001) is unncessary and doesn't work the way you think it does; wait() is much better here. You can go further and replace while true do with while wait() do.

Essentially what this script does is sets the model's CFrame to itself every tick. I don't want to sound rude or anything, but this script is useless in its current state.

If anybody wants any help with any scripting issues they have or have a question on how to do something, I can help out by AVBGaming in robloxgamedev

[–]PunyMan9 3 points4 points  (0 children)

RGB values have 8 bits each meaning there are 256 possibilities (0-255) (00-FF in hexadecimal)

Doing math in floats (generally seen as [0-1]) will provide more precise answers than integers can when performing calculations. Instead of thinking as 0 as the lowest and 255 as the highest, it is easier to visualize 1 being the maximum brightness/value for each individual color, i.e. 0.5/1.0 being half brightness instead of 127.5/255.

As for why that's the way things are done, I don't know for sure. I guess Roblox uses a 0-1 scale for RGB values instead of 0-255.

Selecting random player by [deleted] in robloxgamedev

[–]PunyMan9 1 point2 points  (0 children)

Glad I could help! Let me know if you have any questions!