Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

This Tween script is Correct,But It Does not play, why?

So I am trying to make a spear That Launches when the Player Activates the Spear Tool **NOTE: 2 scripts, One Local, Other Server, (Remote Events)(I am launching the Handle of the tool) **

**local script: **

local tool = script.Parent.Parent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse().Hit.p
local Remote = script.Parent:WaitForChild("RemoteEvent")



tool.Activated:Connect(function()
	
	Remote:FireServer(mouse)
	
end)

**ServerScript: **

local Remote = script.Parent.RemoteEvent
local tool = script.Parent.Parent
local TweenService = game:GetService("TweenService")
local Spear = script.Parent

Remote.OnServerEvent:Connect(function(player,mouse)
	local char = player.Character
	local humanoidrootpart = char.HumanoidRootPart
    local distance = (humanoidrootpart.Position - mouse).Magnitude
local goal = {Position = mouse}

	local info = TweenInfo.new(1,Enum.EasingStyle.Sine,Enum.EasingDirection.Out,0,false,0)	
	local tween = TweenService:Create(Spear,info,goal)
	tween:Play()
	print(distance)
	
end)

**NOTE: print(distance) works and it does print **

I even checked the main Discord for Help, but nobody knows what's the issue with it,I've been trying to fix this for 3 days straight, I am starting to think that this is a studio bug, if it isn't correct me

2 answers

Try this, I think you are missing the 'Hit' property of 'Mouse'.

LocalScript:

local tool = script.Parent.Parent
local player = game.Players.LocalPlayer
local hit = player:GetMouse().Hit
local Remote = script.Parent:WaitForChild("RemoteEvent")



tool.Activated:Connect(function()

    Remote:FireServer(hit)

end)

ServerScript:


local Remote = script.Parent.RemoteEvent
local tool = script.Parent.Parent
local TweenService = game:GetService("TweenService")
local Spear = script.Parent

Remote.OnServerEvent:Connect(function(player,hit)
    local char = player.Character
    local humanoidrootpart = char.HumanoidRootPart
    local distance = (humanoidrootpart.Position - (hit.p)).Magnitude
local goal = {Position = hit.p}

    local info = TweenInfo.new(1,Enum.EasingStyle.Sine,Enum.EasingDirection.Out,0,false,0)  
    local tween = TweenService:Create(Spear,info,goal)
    tween:Play()
    print(distance)

end)

Haven't tested it yet, though. Hope this helps!

local tool = script.Parent.Parent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse().Hit.p
local Remote = script.Parent:WaitForChild("RemoteEvent")



tool.Activated:Connect(function()

    Remote:FireServer(mouse)

end)

mouse currently refers to a Vector3 position. So each time you use mouse, it will always refer to the same Vector3 position.

Consider changing mouse to:

local mouse = player:GetMouse()

Then, when the tool is activated do:

Remote:FireServer(mouse.Hit)

This discussion is preserved as it was. New answers, comments, and votes are closed.