I’m trying to make a magic wand that levitates rocks into the air when you click on them. The script I have in place currently works, but it lifts ALL the rocks at the same time instead of just the target rock that is clicked.
Here is my local script inside the tool
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.Button1Up:Connect(function()
local target = mouse.Target
--print(target)
if target.Name == "Rock" then
game.Workspace.RemoteEvents.LiftRock:FireServer()
else return
end
end)
Then here is the script I have pasted into each rock:
local TweenService = game:GetService("TweenService")
local part = script.Parent
part.Position = part.Position
part.Anchored = true
part.Parent = game.Workspace
local goal = {}
goal.Position = part.Position + Vector3.new(0, 10, 0)
local tweenInfo = TweenInfo.new(1)
local tween = TweenService:Create(part, tweenInfo, goal)
local deb = false
local function raiseRock()
if deb == false then
deb = true
tween:Play()
for i = 1,10,1 do
part.Highlight.OutlineTransparency = part.Highlight.OutlineTransparency - .1
part.Highlight.FillTransparency = part.Highlight.FillTransparency - .08
wait(.1)
end
end
end
game.Workspace.RemoteEvents.LiftRock.OnServerEvent:Connect(raiseRock)
I thought it may have been that I was using a folder for remote events instead of replicated storage, though moving the remote event and changing the script did not allow me to click multiple rocks. It ran once and would not let me click the others.
I have tried passing in the “target” variable from the LocalScript to the server script, and everywhere I have tried seems to suggest the same thing, but it’s registering as the player instead of the clicked part.
How do I pass the target of the mouse into the server script?