Okay, so i’m trying to create a shovel that can dig out terrain. It has a adjustable size value in the script, and bla bla bla, but for some reason, when i pass over the Vector3 to the server script, it says it’s an instance???
LocalScript
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local tool = script.Parent
local replicatedStorage = game:GetService("ReplicatedStorage")
local remote = replicatedStorage:WaitForChild("ShovelEvent")
local size = 3
local function onMouseClick()
local mouseHit = mouse.Hit
if mouseHit then
local position = mouseHit.Position
print("pos:", position)
remote:FireServer(position, size)
end
end
tool.Activated:Connect(onMouseClick)
ServerScript
local replicatedStorage = game:GetService("ReplicatedStorage")
local terrain = workspace.Terrain
local digTerrainEvent = replicatedStorage:WaitForChild("ShovelEvent")
local function digTerrain(position, size)
local cframe = CFrame.new(position)
terrain:FillBall(cframe.Position, size, Enum.Material.Air)
end
digTerrainEvent.OnServerEvent:Connect(digTerrain)
It prints out the position just fine, but that SPECIFIC part just doesn’t work. How do i fix this?
When you fire a remote event from the client, the first parameter is always the player. So position is actually the player who fired it, and size is your position.
To fix:
local function digTerrain(plr, position, size)
end
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local tool = script.Parent
local replicatedStorage = game:GetService("ReplicatedStorage")
local remote = replicatedStorage:WaitForChild("ShovelEvent")
local size = 3
local function onMouseClick()
local mouseHit = mouse.Hit
if mouseHit then
local position = mouseHit.Position
print("pos:", position)
local vec3Pos = Vector3.new(position)
remote:FireServer(player, vec3Pos, size)
end
end
tool.Activated:Connect(onMouseClick)
And the server script:
local replicatedStorage = game:GetService("ReplicatedStorage")
local terrain = workspace.Terrain
local digTerrainEvent = replicatedStorage:WaitForChild("ShovelEvent")
local function digTerrain(player, position, size)
local cframe = CFrame.new(position)
terrain:FillBall(cframe.Position, size, Enum.Material.Air)
end
digTerrainEvent.OnServerEvent:Connect(digTerrain)
I’ll remove the vec3Pos part since it isn’t really necessary. Just forget it exists.
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local tool = script.Parent
local replicatedStorage = game:GetService("ReplicatedStorage")
local remote = replicatedStorage:WaitForChild("ShovelEvent")
local size = 3
local function onMouseClick()
local mouseHit = mouse.Hit
if mouseHit then
local position = mouseHit.Position
print("pos:", position)
remote:FireServer(player, position, size)
end
end
tool.Activated:Connect(onMouseClick)