I'm getting this error message, "Unable to cast value to Object" when I try to call a Remote Function in a Script. I know I have to use a Local Script, but I can't seem to figure out how to call ".Touched" In a Local Script. It just doesn't work..
Script
local levelsHandler = require(game:GetService("ReplicatedStorage").LevelsHandler) local circle = script.Parent.Parent.SpawnPad.Circle local outline = script.Parent.Parent.SpawnPad.Outline local isTouched = false local function chooseRandom(dictionary) local list = {} for key, value in pairs(dictionary) do list[#list+1] = {key = key, value = value} end if #list == 0 then return end return list[math.random(#list)] end function OnTouch(part) local humanoid = part.Parent:WaitForChild("Humanoid") if (humanoid ~= nil) then if isTouched == false then isTouched = true circle.Color = Color3.fromRGB(38, 255, 0) outline.Color = Color3.fromRGB(38, 255, 0) local chosen = chooseRandom(levelsHandler) print("Selected Level: "..chosen.key) game.ReplicatedStorage.CreateLevel:InvokeClient(chosen.key) -- Error end end end script.Parent.Touched:Connect(OnTouch)
heyyyy you need a player parameter in your invoke client!!!!!
https://developer.roblox.com/en-us/api-reference/function/RemoteFunction/InvokeClient
(my stuff above is cringe) here's the line you should replace (29th line):
local PlayerHit = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) game.ReplicatedStorage.CreateLevel:InvokeClient(PlayerHit, chosen.key)