This is a support category for asking questions about how to get something done on the Roblox websites or how to do something on Roblox applications such as Roblox Studio.
You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want to fix my script. the script is trying to make a character for a certain player for new unlocks or Dev-Only Characters
What is the issue? Include screenshots / videos if possible
Nothing happens from the code, it wont move a selected object from on place to another
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Ive tried asking other friends but i still cant find a way
here is the code and i tried to fix all of the errors
local players = game.Players:GetPlayers()
function CheckForRoz()
for i, player in pairs(players) do
if player.Name == "Rozurax" then
print("Test")
if player:FindFirstChild('Character') then
local objectName = "OwnerSilver"
local object = game.Workspace:FindFirstChild(objectName)
if object then
object.Parent = game.ReplicatedStorage.Characters
print("Object moved to ReplicatedStorage.")
else
print("Object not found.")
end
object:Clone().Parent = player:WaitForChild("ReplicatedStorage").Characters
end
end
end
end
game.Players.PlayerAdded:Connect(function()
CheckForRoz()
end)
I am a new scripter and hopefully i can finish this one part of my journey
Oh, well then move the
local players = game.Players:GetPlayers()
inside the CheckForRoz() function. Basically this
function CheckForRoz()
local players = game.Players:GetPlayers() -- we moved it inside so it updates the variable
for i, player in pairs(players) do
if player.Name == "Rozurax" then
print("Test")
if player:FindFirstChild('Character') then
local objectName = "OwnerSilver"
local object = game.Workspace:FindFirstChild(objectName)
if object then
object.Parent = game.ReplicatedStorage.Characters
print("Object moved to ReplicatedStorage.")
else
print("Object not found.")
end
object:Clone().Parent = player:WaitForChild("ReplicatedStorage").Characters
end
end
end
end
Well, did you try making multiple print statements. If you do it might help it also you could wrap the function into a pcall function, to make sure it worked. If it didn’t then just send the errormessage to output. By printing the error message, and making a if success type statement, or whatever your two variables are for success, and error. Then print it works, or the errormessage. Then, from there you can debug the problem.
Instead of looping through all the players in the function, how about loop through all the players, call the function with the player variable, and whenever a player joins, call the function with their player variable (this avoids unintended duplicates)
Also like what @lV0rd said, use UserId, as these are permanent and never change.
That’s true because people can change their usernames, and display names. But, the UserID it’s self will never change. Unless your going onto an alternate account then yes it’d change other then that it wouldn’t change at all.
What, you could do is use :GetChildren() instead of :GetPlayers() function. I find the :GetChildren() typically more reliable with user aspect, and all. So, I don’t really use :GetPlayers() ever. Because you can just use :GetChildren() instead. I feel that it might go better if it’s using :GetChildren() that’s all I’m stating. Because I find the :GetChildren() more reliable with objects, but it can also be used for Players too. It’s just as reliable with objects as it is with players.
local players = game:getService("Players")
local function check(plr)
if plr.UserId ~= game.OwnerId then
return
end
print("player is owner")
-- duplicate
end
players.PlayerAdded:Connect(check)
for _, plr in ipairs(players:GetPlayers()) do
check(plr)
end
local players = game:GetService("Players")
local ownerId = --[[your Id]]
local function check(plr : Player)
if plr.UserId ~= ownerId then
return
end
print("player is owner")
-- duplicate
end
players.PlayerAdded:Connect(check)
for _, plr in ipairs(players:GetPlayers()) do
check(plr)
end
Question real quick why are you trying to clone it into ReplicatedStorage. Because Player doesn’t have ReplicatedStorage so it’s infinitely yielding for that. But, there isn’t a replicatedStorage in a player.
This script would be looking for the name instead of userID. It’s a big script too.
game.Players.PlayerAdded:Connect(function()
local RS = game:GetService(“ReplicatedStorage”)
for i,player in pairs(game.Players:GetChildren()) do
if player.Name == “Rozurax” then
print(“This went through correctly.”)
if player:FindFirstChild(“Character”) then
local objectName = “OwnerSilver”
local object = game.Workspace:FindFirstChild(objectName)
if object then
object.Parent = RS.Characters
print(“Set Object’s Part to ReplicatedStorage.”)
else
print(“Object was not set to replicated, or found.”)
end
local clone = object:Clone()
clone.Parent = RS.Characters
end
end
end
end)
okay so
i made a select character system and the characters to choose from are in replicated storage. i want to make it so a certain player has a specific character thats for like an owner only character, i want to be able to give these characters out to event winners etc. the folder in replicated storage is called “characters” so i was trying to reference that in the script