I’m looking to make it so that when a tool is equipped and the player clicks that a specified object is pulled from the sky and tweens itself to the clicked position.
The issue I’m having is that, while the output does print a “yes” and the “thrown first,” “thrown second” doesn’t appear in output.
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character
local mouse = player:GetMouse()
local tweenserv = game:GetService("TweenService")
local tweeninfo = TweenInfo.new(5)
local equipped = false
script.Parent.Equipped:Connect(function()
equipped = true
print("yes")
end)
script.Parent.Unequipped:Connect(function()
equipped = false
print("no")
end)
mouse.Button1Down:Connect(function()
print("thrown first")
if equipped == true then
print("thrown second")
script.Parent.SendIt:FireServer(mouse.Hit.Position)
end
end)
What am I doing wrong here? This is a localscript.
Doing that only revealed that my mouse1down isn’t even working, nothing is printing when I click. Tool.Activated doesn’t work either, where do I go from here??
Maybe try to convert the local script into a regular script. This has happened many times to me.
Code that would normally work wouldn’t work in a local script. However, when I transferred the code into a “normal” script, it just magically started to work.
I would try that but the issue is that I need to get the player’s mouse, I’m pretty sure I can only do that in a LocalScript, that’s the only reason I’m using a LocalScript.
Maybe try using the .Activated event in the Script instead of getting the mouse and detecting a click (Player:GetMouse() or UserInputService.InputBegan (not gonna write the rest but you prolly know)).
I’m pretty sure the .Activated event only really is detected in server scripts so that’s why it may have not been working in your local script.
I tried this, and absolutely nothing- I had the suspicion that it was the .Activate and so I put a print and I was right- Nothing prints. Give me a second to grab a video.
local Tool = script.Parent
local ObjectToSummon = game.Workspace.ObjectToSummon
local SummonHeight = 20
local SummonTime = 1.5
Tool.Activated:Connect(function()
local Player = game.Players:GetPlayerFromCharacter(Tool.Parent)
if not Player then
return
end
local Mouse = Player:GetMouse()
local ClickPosition = Mouse.Hit.p
local SummonedObject = ObjectToSummon:Clone()
SummonedObject.Parent = game.Workspace
SummonedObject.Position = Vector3.new(ClickPosition.x, ClickPosition.y + SummonHeight, ClickPosition.z)
local ObjectTweenInfo = TweenInfo.new(SummonTime, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local ObjectTween = game:GetService("TweenService"):Create(SummonedObject, ObjectTweenInfo, {Position = ClickPosition})
ObjectTween.Completed:Connect(function()
warn("Tween Finished")
end)
ObjectTween:Play()
end)
How about this, this will give you an idea on if the script started and whether or not the activation process started.
local Tool = script.Parent
local ObjectToSummon = game.Workspace.ObjectToSummon
local SummonHeight = 20
local SummonTime = 1.5
Tool.Activated:Connect(function()
print("Activated")
local Player = game.Players:GetPlayerFromCharacter(Tool.Parent)
if not Player then
print("Player not found")
return
end
local Mouse = Player:GetMouse()
local ClickPosition = Mouse.Hit.p
local SummonedObject = ObjectToSummon:Clone()
SummonedObject.Parent = game.Workspace
SummonedObject.Position = Vector3.new(ClickPosition.x, ClickPosition.y + SummonHeight, ClickPosition.z)
local ObjectTweenInfo = TweenInfo.new(SummonTime, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local ObjectTween = game:GetService("TweenService"):Create(SummonedObject, ObjectTweenInfo, {Position = ClickPosition})
ObjectTween.Completed:Connect(function()
warn("Tween completed")
end)
ObjectTween:Play()
end)
Well I was right, it was the GUI elements which does suck because I was really hoping to have that in my game. I guess I’ll have to find a different way to do this, like using a keybind instead of a click, thank you for helping!