So I decided to make some scripts where when I touch a part, it prompts me a gamepass that gives me extra walkspeed when I buy it. However, when I was done writing the code (I used a remote function to detect the player touching the part, checking if the player has the gamepass, and giving the player the perks) , it gives me the following error message:
> 20:01:32.296 attempt to call a RBXScriptConnection value - Client - GamepassHandler:26
Here are my scripts:
DetectGamepassRequest (Located in the part):
> local part = game.Workspace.Part
> local MarketplaceService = game:GetService("MarketplaceService")
> local gamepassId = 74392253
> local RS = game:GetService("ReplicatedStorage")
> local GamepassFunction = RS.GamepassFunction
>
> part.Touched:Connect(function(otherPart)
> local humanoidCheck = otherPart.Parent:FindFirstChild("Humanoid")
> local player = game.Players:FindFirstChild(otherPart.Parent.Name)
> if humanoidCheck then
> GamepassFunction:InvokeClient(player)
> if not player then
> return
> end
> end
> end
GamepassHandler (Located in StarterPlayerScripts):
> local part = game.Workspace.Part
> local MarketplaceService = game:GetService("MarketplaceService")
> local gamepassId = 74392253
> local RS = game:GetService("ReplicatedStorage")
> local GamepassFunction = RS.GamepassFunction
> local player = game.Players.LocalPlayer
>
> local function promptGamepass()
> local playerUserID = player.UserId
> local hasPass = false
>
> local success, errorMessage = pcall(function()
> hasPass = MarketplaceService:UserOwnsGamePassAsync(playerUserID, gamepassId)
> end)
>
> if not success then
> warn("Error while checking if "..player.Name.."owns the extra walkspeed gamepass. Error info: "..errorMessage)
> return
> end
>
> if hasPass then
> print(player.Name.." already has the walkspeed gamepass!")
> return
> else
> MarketplaceService:PromptGamePassPurchase(player, gamepassId)
> GamepassFunction:InvokeServer(player)
> end
> end
>
> GamepassFunction.OnClientInvoke = promptGamepass()
>
GamepassPerksHandler (Located in StarterPlayerScripts):
> local part = game.Workspace.Part
> local MarketplaceService = game:GetService("MarketplaceService")
> local gamepassId = 74392253
> local RS = game:GetService("ReplicatedStorage")
> local GamepassFunction = RS.GamepassFunction
> local Players = game:GetService("Players")
>
> local function giveGamepassPerks(player, gamePassId, wasPurchased)
> if gamePassId == gamepassId and wasPurchased then
> local char = player.Character
> char.Humanoid.WalkSpeed = 32
> end
> end
>
> local function onJoin(player)
> local UserID = player.UserId
> local hasPass = false
>
> local success, errorMessage = pcall(function()
> hasPass = MarketplaceService:UserOwnsGamePassAsync(UserID, gamepassId)
> end)
>
> if not success then
> warn("Error while checking if "..player.Name.."owns the gamepass! Error info: "..errorMessage)
> return
> end
>
> if hasPass then
> local char = game.Workspace:FindFirstChild(player.Name)
> char.Humanoid.WalkSpeed = char.Humanoid.WalkSpeed*2
> end
> end
>
> GamepassFunction.OnServerInvoke = MarketplaceService.PromptGamePassPurchaseFinished:Connect(giveGamepassPerks)
> Players.PlayerAdded:Connect(onJoin)
If possible, I also don't understand what a RBXScriptConnection is, so if anyone clarifies that would be great.
As always, thank you for your help and I appreciate taking your time out of your day to read this.

1 comment
The scripts you provided caused a script timeout exhaustion. When I added some wait() functions, it no longer lagged, but when I touched the part nothing worked. Any suggestions?