So currently, I have a script that when you touch a specific item, it’ll remove it from the map and change a value. But I have it within a map that I clone from ReplicatedStorage.
This script works if I just leave the map in Workspace, but for whatever reason, it’ll break if I clone the map.
It’s probably something simple that I’m forgetting…but I have no idea why this won’t work.
ServerScript:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local OrbTouched = ReplicatedStorage.RemoteEvents:WaitForChild("OrbTouched")
local Debounce = false
for _, Item in pairs(script.Parent:GetChildren()) do
if Item:IsA("BasePart") then
Item.Touched:Connect(function(hit)
local Character = hit:FindFirstAncestorOfClass("Model")
if not Character then
return
end
local Player = game.Players:GetPlayerFromCharacter(Character)
if not Player then
return
end
if not Debounce then
Debounce = true
OrbTouched:FireClient(game.Players[Character.Name], Item.Name, script.Parent.Parent.Name)--Which gets the levelName)
end
Debounce = false
end)
end
end
Can you show us the code that clones the map? If it’s being cloned locally (in a LocalScript), the server script won’t be able to run because it won’t exist on the server.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local LoadLevel = ReplicatedStorage.RemoteEvents:WaitForChild("LoadLevel")
LoadLevel.OnClientEvent:Connect(function(LevelValue, PlayerName)
if game.Workspace:FindFirstChild("Spawn") ~= nil and game.Workspace:FindFirstChild(LevelValue) == nil then
print(LevelValue)
local LevelToLoad = ReplicatedStorage.Levels[LevelValue]:Clone()
LevelToLoad.Parent = workspace
wait(1)
game.Players[PlayerName].Character:MoveTo(workspace[LevelValue]["Spawn"].Position)
game.Workspace.Spawn:Destroy()
end
end)
Yeah, if a server script is cloned by a LocalScript it won’t run. You’ll have to clone it on the server or find some way to use a LocalScript for that.
I can’t really wrap my head around what you’re trying to accomplish.
But your implementation is broken by design. Just change your approach. Figure out how you can have action X run only on the client. You can mainly achieve this… by running whatever is in your server script… locally on the client. It’ll still modify the map and change a value. Only the server won’t see this value.
If you want the server to see this value. Then you’ll have to again change your approach to the problem.
You could just loop through the children within the local script that clones it. It’s not the cleanest solution, but it’s the simplest and should work fine. You’ll just have to switch to BindableEvents to tell another localscript the item and level name (or whatever it is you’re firing, not sure). It’d look something like this instead for the FireClient part:
With bindables, you don’t need the client as the first argument since it’s just client to client communication. Since the script wouldn’t be directly inside the thing you’re looping through, you’d have to access it some other way.