Is my script incorrect or wrong bcuz its not functioning

i have this script thats not working and i think it should work, any ideas why its not working?

local replicatedStorage = game:GetService("ReplicatedStorage")
local mapValue = replicatedStorage:WaitForChild("Map")

local function onValueChanged()
	print("Hello World")
	if mapValue.Value == "Baseplate" then
		local currentmap = game.Workspace:WaitForChild("Map")
		currentmap:Destroy()

		local newmap = game.ServerStorage.Maps.Baseplate:Clone()
		newmap.Parent = workspace
		newmap.Name = "Map"
	end

	if mapValue.Value == "Crossroad" then
		local currentmap = game.Workspace:WaitForChild("Map")
		currentmap:Destroy()

		local newmap = game.ServerStorage.Maps.Crossroad:Clone()
		newmap.Parent = workspace
		newmap.Name = "Map"
	end
end

mapValue:GetPropertyChangedSignal("Value"):Connect(onValueChanged)

1 Like

whats the output?

hello this is nothing aaaaaaaaa what?

Attempt to connect failed: Passed value is not a function

incorrect reference to the fucntion u tryna connect

wdym
character limit is 30 30 30

local replicatedStorage = game:GetService("ReplicatedStorage")
local mapValue = replicatedStorage:WaitForChild("Map")

local function onValueChanged()
	print("running ok")

	local OLDMap = workspace:FindFirstChild("Map")
	if OLDMap then OLDMap:Destroy() end

	local newMap
	if mapValue.Value == "Baseplate" then
		newMap = game.ServerStorage.Maps.Baseplate:Clone()
	elseif mapValue.Value == "Crossroad" then
		newMap = game.ServerStorage.Maps.Crossroad:Clone()
	end

	if newMap then
		newMap.Parent = workspace
		newMap.Name = "Map"
	end
end

mapValue:GetPropertyChangedSignal("Value"):Connect(onValueChanged)

try this , show the output

its still the same output as before: Attempt to connect failed: Passed value is not a function

ouh bruh whats the map value ?

try this:

local replicatedStorage = game:GetService("ReplicatedStorage")
local mapValue = replicatedStorage:WaitForChild("Map")

local function onValueChanged()
	print("running ok")

	local OLDMap = workspace:FindFirstChild("Map")
	if OLDMap then OLDMap:Destroy() end

	local newMap
	if mapValue.Value == "Baseplate" then
		newMap = game.ServerStorage.Maps.Baseplate:Clone()
	elseif mapValue.Value == "Crossroad" then
		newMap = game.ServerStorage.Maps.Crossroad:Clone()
	end

	if newMap then
		newMap.Parent = workspace
		newMap.Name = "Map"
	end
end

mapValue:GetPropertyChangedSignal("Value"):Connect(function()
onValueChanged()
end)

doesnt work, same error
char limit

I suggest you to use attribute , its more way better and did u update the map value by client or server side?

its from client and how would i use attribute, maybe bcuz its from client thats why it aint working

Have you tried putting outside a local function?

local replicatedStorage = game:GetService("ReplicatedStorage")
local mapValue = replicatedStorage:WaitForChild("Map")

mapValue:GetPropertyChangedSignal("Value"):Connect(function()
  print("running ok")

	local OLDMap = workspace:FindFirstChild("Map")
	if OLDMap then OLDMap:Destroy() end

	local newMap
	if mapValue.Value == "Baseplate" then
		newMap = game.ServerStorage.Maps.Baseplate:Clone()
	elseif mapValue.Value == "Crossroad" then
		newMap = game.ServerStorage.Maps.Crossroad:Clone()
	end

	if newMap then
		newMap.Parent = workspace
		newMap.Name = "Map"
	end
end)

where would i use a local function in this?

No, i meant instead of putting the code inside a local function name(), just put the code directly inside the event (test what i sent)

hm ok ill try that right now
char limit

1 Like

if u mean like this then it doesnt work

local replicatedStorage = game:GetService("ReplicatedStorage")
local mapValue = replicatedStorage:WaitForChild("Map")

local function ChangeMap()
	print("running ok")

	local OLDMap = workspace:FindFirstChild("Map")
	if OLDMap then OLDMap:Destroy() end

	local newMap
	if mapValue.Value == "Baseplate" then
		newMap = game.ServerStorage.Maps.Baseplate:Clone()
	elseif mapValue.Value == "Crossroad" then
		newMap = game.ServerStorage.Maps.Crossroad:Clone()
	end

	if newMap then
		newMap.Parent = workspace
		newMap.Name = "Map"
	end
end

mapValue:GetPropertyChangedSignal("Value"):Connect(ChangeMap)

No i meant test this:

local replicatedStorage = game:GetService("ReplicatedStorage")
local mapValue = replicatedStorage:WaitForChild("Map")

mapValue:GetPropertyChangedSignal("Value"):Connect(function()
  print("running ok")

	local OLDMap = workspace:FindFirstChild("Map")
	if OLDMap then OLDMap:Destroy() end

	local newMap
	if mapValue.Value == "Baseplate" then
		newMap = game.ServerStorage.Maps.Baseplate:Clone()
	elseif mapValue.Value == "Crossroad" then
		newMap = game.ServerStorage.Maps.Crossroad:Clone()
	end

	if newMap then
		newMap.Parent = workspace
		newMap.Name = "Map"
	end
end)

You were putting it inside a local function onValueChanged(), i said to try the script without putting it inside a function.

that aint working too… is it not working bcuz it changed the value from client side?