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 have made a Tool for my planet building game where you can change name of models, since I am planning on removing the F3x Explorer from my game.
What is the issue? Include screenshots / videos if possible!
The name does not change. Is it a client or a server issue? Imma send the scripts below
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Tried debugging, server script doesn’t run
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
CLIENT SCRIPT:
local NameEvent = script.Parent:WaitForChild("NameEvent")
local Tool = script.Parent
local ToolUi = Tool:WaitForChild("ToolGUI")
local ToolTextBox = ToolUi:WaitForChild("TextBox")
local ToolSend = ToolUi:WaitForChild("Send")
local Players = game.Players
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local selectedPlanet = nil
local UserInputService = game:GetService("UserInputService")
local function onMouseClick(input, gpe)
--detect mouse click
if input.UserInputType == Enum.UserInputType.MouseButton1 and gpe == false then
print("Mouse click detected")
local target = mouse.Target
selectedPlanet = target.Parent
if selectedPlanet.ClassName == "Model" then
print("Model detected.")
ToolTextBox.Text = selectedPlanet.Name
else
print("No model detected as Parent of planet, finding ancestors of Model class...")
selectedPlanet = selectedPlanet:FindFirstAncestorOfClass("Model")
if selectedPlanet then
ToolTextBox.Text = selectedPlanet.Name
else
print("No ancestor of class Model detected.")
end
end
end
end
local function equipped()
print("Tool equipped")
ToolUi.Parent = player.PlayerGui
end
local function unequipped()
print("Tool unequipped")
ToolUi.Parent = Tool
end
local function changeName(name)
print("Fired event")
local userId = player.UserId
NameEvent:FireServer(name, selectedPlanet, userId)
end
Tool.Equipped:Connect(equipped)
Tool.Unequipped:Connect(unequipped)
ToolSend.MouseButton1Click:Connect(changeName(ToolTextBox.Text))
UserInputService.InputBegan:Connect(onMouseClick)
SERVER SCRIPT:
local Tool = script.Parent
local NameEvent = Tool.NameEvent
local function onServer(name, selectedPlanet, userId)
--filter the name (considering it is a string)
local TextService = game:GetService("TextService")
local filteredName = nil
local success, errorMessage = pcall(function()
filteredName = TextService:FilterStringAsync(name, userId, Enum.TextFilterContext.PublicChat)
print("[DEBUG] Filtering Name")
end)
if success then
print("[DEBUG] Name successfully filtered")
else
warn("[Filtering Error]: "..errorMessage)
name = "FilteringFail"
end
name = filteredName
selectedPlanet.Name = name
end
NameEvent.OnServerEvent:Connect(onServer)
UPDATES: I have fixed it, but now the issue is with the server script.
(I didn’t modify the server script)
10:21:08.415 [Filtering Error]: Unable to cast Instance to int64 - Server - Script:15
10:21:08.415 Players.dswqsa895.Backpack.Planet Naming Tool.Script:19: attempt to index string with 'Name' - Server - Script:19
When you fire from client to server, player is also added as default parameter with your sent parameters your onServer function should be like this:
local function onServer(player,name, selectedPlanet, userId)
--filter the name (considering it is a string)
local TextService = game:GetService("TextService")
local filteredName = nil
local success, errorMessage = pcall(function()
filteredName = TextService:FilterStringAsync(name, userId, Enum.TextFilterContext.PublicChat)
print("[DEBUG] Filtering Name")
end)
if success then
print("[DEBUG] Name successfully filtered")
else
warn("[Filtering Error]: "..errorMessage)
name = "FilteringFail"
end
name = filteredName
selectedPlanet.Name = name
end
I’ve tried your solution, but these two errors appear:
10:49:07.283 [Filtering Error]: Unable to cast Instance to int64 - Server - Script:15
10:49:07.283 Players.dswqsa895.Backpack.Planet Naming Tool.Script:19: attempt to index string with 'Name' - Server - Script:19
local NameEvent = script.Parent:WaitForChild("NameEvent")
local Tool = script.Parent
local ToolUi = Tool:WaitForChild("ToolGUI")
local ToolTextBox = ToolUi:WaitForChild("TextBox")
local ToolSend = ToolUi:WaitForChild("Send")
local Players = game.Players
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local selectedPlanet = nil
local UserInputService = game:GetService("UserInputService")
local function onMouseClick(input, gpe)
--detect mouse click
if input.UserInputType == Enum.UserInputType.MouseButton1 and gpe == false then
print("Mouse click detected")
local target = mouse.Target
selectedPlanet = target.Parent
if selectedPlanet.ClassName == "Model" then
print("Model detected.")
ToolTextBox.Text = selectedPlanet.Name
else
print("No model detected as Parent of planet, finding ancestors of Model class...")
selectedPlanet = selectedPlanet:FindFirstAncestorOfClass("Model")
if selectedPlanet then
ToolTextBox.Text = selectedPlanet.Name
else
print("No ancestor of class Model detected.")
end
end
end
end
local function equipped()
print("Tool equipped")
ToolUi.Parent = player.PlayerGui
end
local function unequipped()
print("Tool unequipped")
ToolUi.Parent = Tool
end
local function changeName()
local name = ToolTextBox.Text
local userId = player.UserId
print("Fired event")
NameEvent:FireServer(player, name, selectedPlanet, userId)
end
Tool.Equipped:Connect(equipped)
Tool.Unequipped:Connect(unequipped)
ToolSend.MouseButton1Click:Connect(changeName)
UserInputService.InputBegan:Connect(onMouseClick)
Server:
local Tool = script.Parent
local NameEvent = Tool.NameEvent
local function onServer(player,name, selectedPlanet, userId)
--filter the name (considering it is a string)
local TextService = game:GetService("TextService")
local filteredName = nil
local success, errorMessage = pcall(function()
filteredName = TextService:FilterStringAsync(name, userId, Enum.TextFilterContext.PublicChat)
print("[DEBUG] Filtering Name")
end)
if success then
print("[DEBUG] Name successfully filtered")
else
warn("[Filtering Error]: "..errorMessage)
name = "FilteringFail"
end
name = filteredName
selectedPlanet.Name = name
end
NameEvent.OnServerEvent:Connect(onServer)