Place Traffic Cone Position Script Issue

I am trying to make a Place Traffic Cone system for my game, And I can’t get the Server Script correct, It says there’s an error with the script with adding the Cones Position. I was wondering if somebody could help me out with this.

Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Tools = ReplicatedStorage:WaitForChild("Tools")

Tools.PlaceCone.OnServerInvoke = function(Player, ConePlacement)
	if not Player or not ConePlacement then
		return
	end

	local ConeTemplate = Tools.Cones:Clone()
	local ConesFolder = Instance.new("Folder")
	
	ConesFolder.Name = Player.Name .. "'s Cones"
	ConesFolder.Parent = game.Workspace
	ConeTemplate.Parent = ConesFolder
	ConeTemplate.CFrame = CFrame.new(ConePlacement)

	return "Success"
end
2 Likes

Here is a photo of the Error I get in the console

The error says that ConePlacement is a string instead of a vector, can you send the client script that invokes the remote function?

1 Like
PlaceCone:InvokeServer(Parent.Name, u8.CFrame)
1 Like

remote events and functions automatically define the first argument as the player who invoked the event, replace the line on the server script with
.OnServerInvoke = function(Player, parentname, ConePlacement)

2 Likes

So I can remove Player from the function?

1 Like

if Parent.Name is the player, yes you can remove it

2 Likes

No, Player was the Player who invoked the event, So than I can name the folder [Player]'s Cones

what exactly is Parent.Name supposed to be and why are you sending it? it doesnt seem like youre using it so you can just remove it, either that or add that extra argument on the server script that i said above

1 Like

Why would you use CFrame.new(conePlacement) if conePlacement is already a CFrame
You can directly do ConeTemplate.CFrame = ConePlacement ?

2 Likes

when you Invoke the server, it should already send over the player as the first parameter. In your .OnServerInvoke, you should define the player, coneplacement, and the CFrame.
It should be something like .OnServerInvoke(player, objectname, objectCFrame)

Basically you need to define the all of the messages sent from the client. Im not sure what you need the name of the object for but you have to define it in their server script if you send it over from the client

The reason you are getting the “vector3 expected, got string” is because you are only sending the objectname over and not the CFrame value. (Hopefully this makes sense in typing this on mobile)

2 Likes

So then it would be .OnServerInvoke(Player, Cone, Position)
Something like that?

It worked! Thank you so much!!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.