#script works only if the startercharacter is that character(read the code)

1 messages · Page 1 of 1 (latest)

ashen pollen
#

``local UIS = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local event = ReplicatedStorage:FindFirstChild("Events"):FindFirstChild("ShootEvent")
local Players = game:GetService("Players")
local CS = game:GetService("CollectionService")
local plr = Players.LocalPlayer
local cd = true
local sound = script["spy revolver fire sound"]

UIS.InputBegan:Connect(function(input, gameProcessedEvent)
local character = plr.Character or plr.CharacterAdded:Wait()
if CS:HasTag(plr.Character, "Character") then
if character.Name == "Cowboi" then
if gameProcessedEvent then return end
if input.UserInputType == Enum.UserInputType.MouseButton3 and cd == true then -- MouseButton3 is middle mouse
cd = false
print("yay")
local char = plr.Character or plr.CharacterAdded:Wait()
local revolver = char.Revolver
if revolver then
local shootFrom = revolver:FindFirstChild("ShootFrom")
if shootFrom then
local shootCF = shootFrom.CFrame
event:FireServer(char, shootCF) -- send CFrame, not Position
else
warn("ShootFrom part not found in Revolver")
end
else
warn("Revolver not found in character")
end
sound:Play()
task.wait(5)
cd = true
print("cd done")
end
end
end
end)``

If i put the Cowboi(with tags and revolver)
And the script is in the StarterPlayerScripts
Then it works perfectly

But if i make it when u press a button it changes u to that starter character then it wont work(it is in replicatedstorage and puts it into playerscripts this time its not in StarterPlayerScripts)

gray quail
strong wyvern
#

❌ Why it breaks when cloning manually from ReplicatedStorage
When you manually clone a LocalScript from ReplicatedStorage and insert it into PlayerScripts, two things can go wrong:

It runs too early – before the new character ("Cowboi") is fully loaded and tagged.

It only runs once – and may miss character changes (especially if your game swaps characters dynamically).

#

the solution is: You need to wait until the "Cowboi" character is fully inserted and tagged after switching characters.

ashen pollen
late brook