I need help with my script there's no errors

I spent an hour trying to fix this script I have no idea why it’s not working help!

– the script checks if a player has a gamepass then it gives the player an arrow to a destination.

Thank you everyone who helped me!)

local function compas()
local ArrowModel = game.ReplicatedStorage:WaitForChild(“ArrowModel”):Clone()
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
ArrowModel.Parent = workspace
ArrowModel.Name = player.Name…“'s Arrow”
game:GetService(“RunService”).RenderStepped:Connect(function()
ArrowModel.PrimaryPart.CFrame = CFrame.new(char.HumanoidRootPart.Position, workspace.ArrowPart.Position)
end) end

function Close(player)
if game:GetService(“MarketplaceService”):UserOwnsGamePassASync(player, 5694417) then
compas()
else
script:Destroy()
end
end
local Players = game:GetService(“Players”)
Players.PlayerAdded:connect(Close)

– sorry the script is a mess I’m new lul

it would be a lot easier if you would indent your script I have no idea what’s going on

3 Likes

Sorry I split them up into 3 main parts the first are the variables, second where the arrow is made and attached to the local player, and the third where it checks if the player has a gamepass and gives them the arrow. (the arrow is hidden until it finds the gamepass)

whats this???
wheres the end

3 Likes

I messed up hgfgfh I meant two main parts lul, the first is where the arrow is made and attached and 2nd is where the gamepass is checked sorry.

the ends shouldn’t be in the same place

2 Likes

can you put some prints() in every event

3 Likes

(not contributing to the problem)
if you want your post to look better you can wrap the code like this:
Screenshot_3116
so it looks like:

print("hi")

i also recommend to indent the script like @ZINTICK said due to it being really hard to read (if you don’t know what it is you can look it up, there is an auto-indent setting in studio). indenting scripts makes it much easier to find bugs ^^

4 Likes

im not good in scripting maybe try this

local function compas()
local ArrowModel = game.ReplicatedStorage:WaitForChild(“ArrowModel”):Clone()
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
ArrowModel.Parent = workspace
ArrowModel.Name = player.Name…"'s Arrow"
game:GetService(“RunService”).RenderStepped:Connect(function()
ArrowModel.PrimaryPart.CFrame = CFrame.new(char.HumanoidRootPart.CFrame, workspace.ArrowPart.CFrame)
end) 
end
4 Likes

UserOwnsGamePassAsync expects a userId, not the player Instance

But sinec it’s not erroring, something else going on, what type of script is it and where is it located?

2 Likes
function Close(player)
if game:GetService(“MarketplaceService”):UserOwnsGamePassASync(player.UserId, 5694417) then
compas()
else
script:Destroy()
end
end
local Players = game:GetService(“Players”)
Players.PlayerAdded:connect(Close)
1 Like

maybe variablize the runService

2 Likes

Too many comments my brain is going to explode but uh its a local script in startercharacterscripts.

1 Like

indent your scripts please!!!

2 Likes

i am on mobile phone sorry.

:pleading_face::pleading_face::pleading_face:

3 Likes

That’s why it doesn’t work, PlayerAdded doesn’t work for your localPlayer in a localscript, your palyer is added to fast before the script detects it, use this

local player = game.Players.LocalPlayer

local function compas()
	local ArrowModel = game.ReplicatedStorage:WaitForChild(“ArrowModel”):Clone()
	local char = player.Character or player.CharacterAdded:Wait()
	ArrowModel.Parent = workspace
	ArrowModel.Name = player.Name…"'s Arrow"
	game:GetService("RunService").RenderStepped:Connect(function()
		ArrowModel:SetPrimaryPartCFrame(CFrame.new(char.HumanoidRootPart.Position, workspace.ArrowPart.Position))
	end)
end

if game:GetService("MarketplaceService"):UserOwnsGamePassASync(player.UserId, 5694417) then
	compas()
else
	script:Destroy()
end
2 Likes

use
:SetPrimaryPartCFrame() insead

1 Like

try using print() statements

1 Like

There was some mistakes with your script I fixed them, but still I don’t see any errors nor the arrow.


local function compas()
	local ArrowModel = game.ReplicatedStorage:WaitForChild("ArrowModel"):Clone()
	local char = player.Character or player.CharacterAdded:Wait()
	ArrowModel.Parent = workspace
	ArrowModel.Name = player.Name .." 's Arrow" 
	game:GetService("RunService").RenderStepped:Connect(function()
		ArrowModel:SetPrimaryPartCFrame(CFrame.new(char.HumanoidRootPart.Position, workspace.ArrowPart.Position))
	end)
end

if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 5694417) then
	compas()
else
	script:Destroy()
end
1 Like

Are you testing it ingame or in studio? Do you own the gamepass? Add a print i nthe compas function to see if it’s actually running

1 Like