Having Problem When converting to local script

Script was on simple script when i did it on local script stopped working please can anyone help?

local arrow = game.Workspace.Arrow

local Service = game:GetService(“TweenService”)

local Info = TweenInfo.new(

1,

Enum.EasingStyle.Quad,

Enum.EasingDirection.Out,

0,

false,

0.5

)

local Loop = false

local i = game.Workspace.Checkpoint3

local Anim = {Position = i.Position + Vector3.new(0, 10, 0)}

local Tween = Service:Create(arrow,Info,Anim)

script.Parent.Touched:Connect(function()

Tween:Play()

script.Disabled = true

end)

2 Likes

I’m assuming because you’re using a local script but it’s located in workspace - local scripts don’t run in there.

1 Like

The reason is you cant detect .Touched events from a local script, to do this from a local script you would need to fire events or use remote functions.

1 Like

Wdym, .Touched event does fire in local scripts.

1 Like

What i can do please Help me i dont have any idea about remote events

As I already said, local scripts don’t run in workspace, place it in StarterPlayerScripts and modify paths to the objects in your script.

2 Likes

The name of “local” scripts imply it is ran by the player, so placing it in a part not related to the player it will not run. You can solve this by placing the local script in one of the player objects. (keep in mind other players will not be able to see what happens in a localscript except the player it is in. (personally I would probably find some fancy way of doing it.)

1 Like

@WingedDash i tried same on starterplayerscripts but it will not working can you help me please?

The reason you are experiencing this issue is because LocalScripts run on the client. If you want to stick with LocalScripts you must parent them somewhere in the Client such as PlayerGui or StarterPlayerScripts.

The second issue is that you are connecting your .Touched event to script.Parent which won’t work because your new parent will be either PlayerGui or StarterPlayerScripts. You must localize your instance such as local part = workspace.Path.To.Part then part.Touched:Connect(...).

2 Likes

local part = game.workspace.Checkpoint1.To,Part what is To in this?

He means you should change

to

game.Workspace.Checkpoint3.Touched:Connect(function()

I meant unless it’s situated in the character or PlayerGui.

i did it too but it kept visible for all players

Put it in a local script in starter player scripts.

i putted on starterplayerscripts on local script but it still visible for all players

There’s no way, changes on one client don’t replicate to other clients.

1 Like

i will try again and make video if it not work but if it works i wil give the solution to your reply

This is because when one player touches the part, every client will register the touch. You need to use Players:GetPlayerFromCharacter to ensure the Player.LocalPlayer is the player who touched the part:

local players = game:GetService("Players")
local localPlayer = players.LocalPlayer

part.Touched:Connect(function(otherPart)
    local character = otherPart.Parent
    local player = players:GetPlayerFromCharacter(character)
    if player ~= localPlayer then return end
    -- continue...
end)
3 Likes

Thanks @BenSBk for information it will be helpfull for me!