What do you want to achieve?
I want to send Player Name from Text Box through Remote Function.
What is the issue?
ServerScriptService.petgivescript:4: attempt to concatenate string with nil
What solutions have you tried so far?
I tried to find solution here on DevForum but I didnt come with a solution.
Local Script inside StarterGui:
local Button = script.Parent:WaitForChild("Button")
local AcceptFrame = script.Parent.Parent.Parent.Parent.Parent.AcceptFrame
local PetChosen = script.Parent.Parent.Parent.Parent.Parent.PetSelector.PetSelectorFramer.PetSelectorBox
local PlayerName = script.Parent.Parent.Parent.Parent.Parent.PlayerNameSelectorX.PlayerNameFramer.PlayerNameBox
Button.MouseButton1Click:Connect(function()
game.ReplicatedStorage.Folder.RemoteClone:InvokeServer(PetChosen.Text, PlayerName.Text)
game.ReplicatedStorage.Folder.RemoteID:InvokeServer(PlayerName.Text)
AcceptFrame.Visible = false
print("invoked")
end)
Script inside ServerScriptService:
local RS = game.ReplicatedStorage
function RandomID(Player, PlayerName)
print("1 "..PlayerName)
local Rand = math.random(2,1000000)
print("2 "..PlayerName)
for i,v in pairs (game.Players:FindFirstChild(PlayerName).Pets:GetChildren()) do
print("3 "..PlayerName)
if v.PetID.Value == Rand then
print("4 "..PlayerName)
return RandomID()
end
end
return Rand
end
RS.Folder.RemoteID.OnServerInvoke = RandomID
local function getpetrandom(Player, PetChosen, PlayerName)
print(PetChosen.."1")
local Settings = RS.Pets.Models:FindFirstChild(PetChosen).Settings
if 1+1 == 2 then
print(PetChosen.."2")
local Clone = RS.Pets.PetFolderTemplate:Clone()
Clone.PetID.Value = RandomID(PlayerName)
Clone.Multiplier1.Value = Settings.Multiplier1.Value
Clone.Multiplier2.Value = Settings.Multiplier2.Value
print(PetChosen.."3")
Clone.Type.Value = "Normal"
Clone.Parent = PlayerName.Pets
print(PetChosen.."5")
Clone.Name = PetChosen
end
return PetChosen
end
RS.Folder.RemoteClone.OnServerInvoke = getpetrandom
Thanks for any solution Ive been trying to fix this for while now :).
I am getting PetChosen and both PlayerNames from the Local Script inside StarterGui as you can see.
PetChosen and both player names are Texts and I am trying to invoke server with them.
My mistake, I was thinking completely differently. I honestly have no clue why this wouldn’t work. Hopefully a more advanced developer can solve your issue.
You’ve used RS.Folder.RemoteID.OnServerInvoke = RandomID.
While this will fire when the server is invoked, you are not passing the player name as an argument through the RandomID function, therefore when the function looks for PlayerName it will come up with nil.
use RS.Folder.RemoteID.OnServerInvoke = RandomID(Player,PlayerName) instead.
I believe you are incorrect. He was doing it correctly. Putting the parenthesis with it like how you did it will invoke the function once the script runs and make an error. It should be tested anyways but just giving my insight.
You should try to print the PlayerName in the local script and see if you are getting anything there. It is likely that the PlayerName you are passing itself is nil, which makes it so that the server script is receiving nil as well.
Why would he do this? It’s redundant to do that when you can just write it in a single line like he did. It will still pass the arguments correctly as long as they’re defined in the function itself.
No, that’s calling the function with null arguments.
When the function is automatically called, it passes the arguments as seen in the documentation
The issue here is most likely a replication error between the client and server
Yea it is still saying nil.
game.ReplicatedStorage.Folder.RemoteID:InvokeServer(“String for test”)
Error:
ServerScriptService.petgivescript:4: attempt to concatenate string with nil