Hello, Am Begginer Scripter That Making Lasso System For My Game, That If You Throw Lasso To Player, Player Sended To Jail, And You Get Money, Problem Is That I Don’t Know How To Get Player, This Is My Script
Script Inside Lasso Tool
local Tool = script.Parent
local Handle = Tool.Handle
local MouseLoc = Tool:WaitForChild("MouseLoc",10)
Tool.Enabled = true
local vPlayer = Tool.Parent.Parent
local vCharacter = vPlayer.Character or vPlayer.CharacterAdded:Wait()
function fire(direction)
Tool.Enabled = false
local anim = Instance.new("Animation")
anim.Name = "ThrowAnim"
anim.AnimationId = "rbxassetid://13181333852"
local track
track = script.Parent.Parent.Humanoid:LoadAnimation(anim)
track.Priority = Enum.AnimationPriority.Movement
track.Looped = true
track:Play()
task.wait(0.8)
Handle.Transparency = 1
local lasso = Instance.new("Part")
local spawnPos = vCharacter.PrimaryPart.Position
spawnPos = spawnPos + (direction * 5)
lasso.Position = spawnPos
lasso.Size = Vector3.new(2,2,2)
lasso.Velocity = direction * 200
lasso.BrickColor = BrickColor.new('Cashmere')
lasso.Shape = 0
lasso.Locked = true
lasso.BottomSurface = 0
lasso.TopSurface = 0
lasso.Name = "ThrowedLasso"
lasso.Elasticity = 1
lasso.Reflectance = .2
lasso.Friction = 0
lasso.Orientation = Vector3.new(0, -90, 0)
local A1 = Instance.new("Attachment", vCharacter["Right Arm"])
local A2 = Instance.new("Attachment", lasso)
local lineForce = Instance.new("LineForce",lasso)
lineForce.Attachment0 = A2
lineForce.Attachment1 = A1
lineForce.Magnitude = 200
local rotation = Instance.new("BodyAngularVelocity", lasso)
rotation.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
rotation.AngularVelocity = Vector3.new(0,30,0)
local spring = Instance.new("SpringConstraint", lasso)
spring.Attachment0 = A1
spring.Attachment1 = A2
spring.Visible = true
spring.Coils = 0
spring.Color = lasso.BrickColor
local scriptt = game.ServerStorage.Lasso:Clone()
scriptt.Parent = lasso
Handle.Mesh:Clone().Parent = lasso
Handle.FlyingSound:Clone().Parent = lasso
local new_script = script.Parent.CannonBall:Clone()
new_script.Disabled = false
new_script.Parent = lasso
local creator_tag = Instance.new("ObjectValue")
creator_tag.Value = vPlayer
creator_tag.Name = "creator"
creator_tag.Parent = lasso
lasso.Parent = workspace
task.wait(2.5)
lasso:Destroy()
Handle.Transparency = 0
Tool.Enabled = true
end
function onActivated()
if not Tool.Enabled then
return
end
local character = Tool.Parent;
local humanoid = character:FindFirstChildOfClass("Humanoid")
if not humanoid then
print("Humanoid not found")
return
end
local targetPos = MouseLoc:InvokeClient(game:GetService("Players"):GetPlayerFromCharacter(character))
local lookAt = (targetPos - character.Head.Position).unit
fire(lookAt)
end
Tool.Activated:Connect(onActivated)
Script When Player Touched Lasso [this script is where i want to get player that used lasso, also this script is in inside of serverstorage]
script.Parent.Touched:Connect(function(hit)
local char = hit.Parent
local hum = char:FindFirstChild("HumanoidRootPart")
local head = char:FindFirstChild("Head")
local foundgui = head:FindFirstChild("WantedGUI")
if hit.Parent:FindFirstChild("Humanoid") ~= nil and foundgui then
local pos = game.Workspace:WaitForChild("JailSpawn").CFrame + Vector3.new(0,5,0)
hum.CFrame = pos
script.Parent:Destroy()
foundgui:Destroy()
char.FindFirstChild("Script"):Destroy()
task.wait(50)
local pos2 = game.Workspace:WaitForChild("Spawn").CFrame + Vector3.new(0,5,0)
hum.CFrame = pos2
end
end)
Where do you wanna get the player? I mean in which script? And which player? the owner of tool or the target player?
And you want to get the Player Instance right? cause you already have the Character.
Example:
local char = hit.Parent
local player = game.Players:GetPlayerFromCharacter(char)
The second script you said its in ServerStorage? How are you making it run? I mean, none scripts run in ServerStorage, are you cloning it and giving it to player when its needed?
If the script is in the tool at the end, just add these lines, those will run when the script runs by first time, which is when its added into the player’s tool and tool into player:
local CharacterThatOwnsTheTool = script.Parent.Parent
local ThePlayerInstance = game.Players:GetPlayerFromCharacter(CharacterThatOwnsTheTool)
script.Parent.Touched:Connect(function(hit)
local char = hit.Parent
local hum = char:FindFirstChild("HumanoidRootPart")
local head = char:FindFirstChild("Head")
local foundgui = head:FindFirstChild("WantedGUI")
if hit.Parent:FindFirstChild("Humanoid") ~= nil and foundgui then
local pos = game.Workspace:WaitForChild("JailSpawn").CFrame + Vector3.new(0,5,0)
hum.CFrame = pos
script.Parent:Destroy()
foundgui:Destroy()
char.FindFirstChild("Script"):Destroy()
task.wait(50)
local pos2 = game.Workspace:WaitForChild("Spawn").CFrame + Vector3.new(0,5,0)
hum.CFrame = pos2
end
end)
For the script inside the lasso, you’re going to want to change the vPlayer and vCharacter to this because when a tool is equip it is no longer inside of the player backpack and is insead inside of the character model
local vCharacter = Tool.Parent.Parent
local vPlayer = game.Players:GetPlayerFromCharacter(vCharacter)
This Is One Of Code That Is On First Script, And Am Trying To Clone Second Script To This Lasso Parts That I Spawned With Instance.new [Sorry If I Misunderstand What You Try To Say]
Oh, I found it in your original script in the post, you are parenting Lasso to workspace.
Parent it to the character or a tool which belongs to the player.
If you parent the Lasso Part to a tool that belongs to player, or into the player’s character you will be able to find easily the player who owns the Lasso in the script, by using the lines I sent in previous messages:
local CharacterThatOwnsTheTool = script.Parent.Parent
local ThePlayerInstance = game.Players:GetPlayerFromCharacter(CharacterThatOwnsTheTool)
Hello, Sorry For Late Response, But Somehow, It Not Worked. Here Is Script
local CharacterThatOwnsTheTool = script.Parent.Parent
local ThePlayerInstance = game.Players:GetPlayerFromCharacter(CharacterThatOwnsTheTool)
script.Parent.Touched:Connect(function(hit)
local char = hit.Parent
local hum = char:FindFirstChild("HumanoidRootPart")
local head = char:FindFirstChild("Head")
local foundgui = head:FindFirstChild("WantedGUI")
if hit.Parent:FindFirstChild("Humanoid") ~= nil and foundgui then
local pos = game.Workspace:WaitForChild("JailSpawn").CFrame + Vector3.new(0,5,0)
hum.CFrame = pos
script.Parent:Destroy()
foundgui:Destroy()
char.FindFirstChild("Script"):Destroy()
ThePlayerInstance.leaderstats.Gold.Value = ThePlayerInstance.leaderstats.Gold.Value + 350
task.wait(50)
local pos2 = game.Workspace:WaitForChild("Spawn").CFrame + Vector3.new(0,5,0)
hum.CFrame = pos2
end
end)